In Computer Programming, an operator is a symbol that performs operations on a value or a variable.
For example, + is an operator that is used to add two numbers.
Go programming provides wide range of operators that are categorized into following major categories:
Arithmetic operators
Assignment operator
Relational operators
Logical operators
We use arithmetic operators to perform arithmetic operations like addition, subtraction, multiplication, and division.
Here's a list of various arithmetic operators available in Go.
| Operators | Example |
|---|---|
+ (Addition) | a + b |
- (Subtraction) | a - b |
* (Multiplication) | a * b |
/ (Division) | a / b |
% (Modulo Division) | a % b |
Output
Output
In the above example, we have used the / operator to divide two numbers: 11 and 4. Here, we get the output 2.
However, in normal calculation, 11 / 4 gives 2.75. This is because when we use the / operator with integer values, we get the quotients instead of the actual result.

If we want the actual result we should always use the / operator with floating point numbers. For example,
Output
Here, we get the actual result after division.
In the above example, we have used the modulo operator with numbers: 11 and 4. Here, we get the result 3.
This is because in programming, the modulo operator always returns the remainder after division.

The modulo operator is always used with integer values.
In Golang, we use ++ (increment) and -- (decrement) operators to increase and decrease the value of a variable by 1 respectively. For example,
In the above example,
num++ - increases the value of num by 1, from 5 to 6
num-- - decreases the value of num by 1, from 5 to 4
We have used ++ and -- as prefixes (before variable). However, we can also use them as postfixes (num++ and num--).
There is a slight difference between using increment and decrement operators as prefixes and postfixes. To learn the difference, visit Increment and Decrement Operator as Prefix and Postfix.
We use the assignment operator to assign values to a variable. For example,
Here, the = operator assigns the value on right (34) to the variable on left (number).
In the above example, we have used the assignment operator to assign the value of the num variable to the result variable.
In Go, we can also use an assignment operator together with an arithmetic operator. For example,
Here, += is additional assignment operator. It first adds 6 to the value of number (2) and assigns the final result (8) to number.
Here's a list of various compound assignment operators available in Golang.
| Operator | Example | Same as |
|---|---|---|
+= (addition assignment) | a += b | a = a + b |
-= (subtraction assignment) | a -= b | a = a - b |
*= (multiplication assignment) | a *= b | a = a * b |
/= (division assignment) | a /= b | a = a / b |
%= (modulo assignment) | a %= b | a = a % b |
We use the relational operators to compare two values or variables. For example,
Here, == is a relational operator that checks if 5 is equal to 6.
A relational operator returns
true if the comparison between two values is correct
false if the comparison is wrong
Here's a list of various relational operators available in Go:
| Operator | Example | Descriptions |
|---|---|---|
== (equal to) | a == b | returns true if a and b are equal |
!= (not equal to) | a != b | returns true if a and b are not equal |
> (greater than) | a > b | returns true if a is greater than b |
< (less than) | a < b | returns true if a is less than b |
>= (greater than or equal to) | a >= b | returns true if a is either greater than or equal to b |
<= (less than or equal to) | a <= b | returns true is a is either less than or equal to b |
To learn more, visit Go relational operators.
We use the logical operators to perform logical operations. A logical operator returns either true or false depending upon the conditions.
| Operator | Description | Example |
|---|---|---|
&& (Logical AND) | exp1 && exp2 | Returns true if both expressions exp1 and exp2 are true. |
|| (Logical OR) | exp1 || exp2 | Returns true if at least one of the expressions exp1 or exp2 is true. |
! (Logical NOT) | !exp | Returns true if exp is false, and false if exp is true. |
To learn more, visit Go relational operators.