Go Operators

Go Tutorial

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:

  1. Arithmetic_Operators

  2. Relational (Comparison) Operators

  3. Logical_Operators

  4. Assignment_Operators

  5. Bitwise_Operators

  6. Unary_Operators

  7. Miscellaneous_Operators


 Arithmetic Operators

Used for mathematical calculations.

OperatorMeaningExample
+Additiona + b
-Subtractiona - b
*Multiplicationa * b
/Divisiona / b
%Modulusa % b
  •  Integer division truncates decimals.

 Relational (Comparison) Operators

Used to compare values; result is bool.

OperatorMeaning
==Equal to
!=Not equal
>Greater than
<Less than
>=Greater or equal
<=Less or equal

Logical Operators

Used with Boolean expressions.

OperatorMeaning
&&Logical AND
`
!Logical NOT

 


Assignment Operators

Assign values to variables.

OperatorExampleMeaning
=a = 10Assign
+=a += 5a = a + 5
-=a -= 2a = a - 2
*=a *= 3a = a * 3
/=a /= 2a = a / 2
%=a %= 2a = a % 2

Unary Operators

Operate on a single operand.

OperatorMeaning
+Unary plus
-Unary minus
!Logical NOT
*Pointer dereference
&Address-of

 


Bitwise Operators

Operate on bits (used in systems, flags, performance code).

OperatorMeaning
&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):

  1. * / %

  2. + -

  3. == != < > <= >=

  4. &&

  5. ||

Use parentheses to be safe:

result := (a + b) * c

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 expressions

  • Bitwise-operator are powerful but advanced

  • Must-know for Go interviews & backend dev

You may also like...