Go Operators

Go Operators – Complete Tutorial
In Go (Golang), operators are symbols used to perform operations on variables and values—such as arithmetic, comparison, logic, assignment, and bit manipulation.
They are fundamental to control flow, calculations, and conditions.
Types of Operators in Go
Go operators are grouped into these categories:
Arithmetic_Operators
Relational (Comparison) Operators
Logical_Operators
Assignment_Operators
Bitwise_Operators
Unary_Operators
Miscellaneous_Operators
Arithmetic Operators
Used for mathematical calculations.
| Operator | Meaning | Example |
|---|---|---|
+ | Addition | a + b |
- | Subtraction | a - b |
* | Multiplication | a * b |
/ | Division | a / b |
% | Modulus | a % b |
- Integer division truncates decimals.
Relational (Comparison) Operators
Used to compare values; result is bool.
| Operator | Meaning |
|---|---|
== | Equal to |
!= | Not equal |
> | Greater than |
< | Less than |
>= | Greater or equal |
<= | Less or equal |
Logical Operators
Used with Boolean expressions.
| Operator | Meaning |
|---|---|
&& | Logical AND |
| ` | |
! | Logical NOT |
Assignment Operators
Assign values to variables.
| Operator | Example | Meaning |
|---|---|---|
= | a = 10 | Assign |
+= | a += 5 | a = a + 5 |
-= | a -= 2 | a = a - 2 |
*= | a *= 3 | a = a * 3 |
/= | a /= 2 | a = a / 2 |
%= | a %= 2 | a = a % 2 |
Unary Operators
Operate on a single operand.
| Operator | Meaning |
|---|---|
+ | Unary plus |
- | Unary minus |
! | Logical NOT |
* | Pointer dereference |
& | Address-of |
Bitwise Operators
Operate on bits (used in systems, flags, performance code).
| Operator | Meaning |
|---|---|
& | AND |
| ` | ` |
^ | XOR |
<< | Left shift |
>> | Right shift |
Increment / Decrement (Special Rule)
Go does not allow ++ or -- in expressions.
- Interview favorite trick question.
Operator Precedence
Order in which operators are evaluated.
High → Low (simplified):
* / %+ -== != < > <= >=&&||
Use parentheses to be safe:
Miscellaneous Operators
&→ address of variable*→ pointer dereference
Common Mistakes
- Expecting float division with integers
- Using
++inside expressions - Confusing
&(address) with bitwise AND - Ignoring operator precedence
Interview Questions & MCQs
Q1. What does a / b return for integers?
A) Float
B) Integer
C) Error
D) String
Answer: B
Q2. Is ++i allowed in Go?
A) Yes
B) No
Answer: B
Q3. Which operator checks equality?
A) =
B) ==
C) :=
D) ===
Answer: B
Q4. Logical AND operator in Go?
A) &
B) &&
C) and
D) ||
Answer: B
Q5. Which operator gets address of variable?
A) *
B) #
C) &
D) @
Answer: C
Real-Life Use Cases
- Conditions & validations
- Calculations
- Bit flags & masks
- Pointer-based operations
- Performance-critical code
Summary
Go has rich operator support
Arithmetic, logical, relational are most common
Integer division truncates decimals
++/--are statements, not expressionsBitwise-operator are powerful but advanced
Must-know for Go interviews & backend dev
