GoLang

Explain Operators in Go Programming Language | Go Programming Tutorial

Explain Operators in Go Programming Language | Go Programming Tutorial

Explain Operators in Go Programming Language | Go Programming Tutorial

In this article, you will learn:

  • What are Operators?
  • Explain different types of operators in Go Programming Language

What are Operators?

Operators are the basis of any programming language. The Go language is incomplete without the use of operators. Operators allow us to perform multiple operations on operands. It is categorized based on different functionality:

  • Arithmetic Operators
  • Relational Operators
  • Logical Operators
  • Bitwise Operators
  • Assignment Operators
  • Misc Operators

Arithmetic Operators

These operators are used to perform the arithmetic operations on operators in the Go language:

  • Addition: The ‘+’ operator used to add two operands
  • Subtraction: The ‘-’ operator used to subtract two operands
  • Multiplication: The “*” operator used to multiply two operands
  • Division: The ‘/’ operator divided the first operand by the second
  • Modulus: The ‘%’ operator returns the remainder after performing the division.

Relational Operators

These operators are used for the comparison of two values. These operators are:

  • ‘==’(Equal To): It checks whether the given operands are equal or not. It is equal, it returns true, otherwise false.
  • ‘!=’(Not Equal To): It also checks the same thing as above. The only difference is that it returns true if the operands are not equal and vice versa.
  • ‘>’(Greater Than): It checks whether the first operand is greater than the other operand. If it satisfies the condition, it returns true. Otherwise, it returns false.
  • ‘<’(Less Than): It checks whether the first operand is less than the other operand. If it satisfies the condition, it returns true else false.
  • ‘>=’(Greater than Equal To): It checks whether the first operand is greater than or equal to another operand. If it satisfies, it returns true. Otherwise, it returns false.
  • ‘<=’(Less Than Equal To): It checks whether the first operand is less than or equal to another operand. If it satisfies, it returns true. Otherwise, it returns false.

Logical Operators

These are used to combine two or more conditions. 

  • Logical AND: The ‘&&’ operator returns true when both the LHS is equal to RHS. Otherwise, it returns false.
  • Logical OR: The ‘| |’ operator returns true only when one condition is satisfied. Otherwise, it returns false.
  • Logical NOT: The ‘!’ operator returns true if the given condition is not satisfied.

 

Please refer to the next article to understand the other three operators. 

Yamini  Sharma

I am working as a professional engineer in "HIghRadius Technologies Pvt. Ltd." Passionate about learning and exploring new technologies. Enthusiast in writing and sharing what I have in my knowledge bucket.