codingstuff.io
ExploreTutorialsProblemsCS Subjects
Get Started
ExploreTutorialsProblemsCS Subjects
Get Started
codingstuff.io

Master the art of building software through interactive tutorials, real-world problems, and guided projects.

Pune, Maharashtra, India

codingstuffmail@gmail.com

Product

  • Explore
  • Tutorials
  • Problems
  • CS Subjects

Company

  • About
  • Contact
  • Privacy Policy
  • Terms & Conditions
  • Sitemap

© 2026 codingstuff.io. All rights reserved.

Built with ❤️ for developers everywhere

/
/
All Tutorials
🐹

Go (Golang)

6 / 72 topics
1Introduction to Go (Golang)2Installation and Setup3Hello World Program4Variables and Constants5Data Types6Operators7Control Structures (if, else, switch)8Functions9Defer Statement10Panic and Recover
Tutorials/Go (Golang)/Operators
🐹Go (Golang)

Operators

Updated 2026-05-15
10 min read

Operators

Introduction

In Go, operators are symbols that perform operations on operands (variables or values). They are essential for performing calculations, comparisons, logical operations, and more. This tutorial will cover the basic types of operators available in Go, including arithmetic, comparison, logical, and bitwise operators.

Concept

Arithmetic Operators

Arithmetic operators are used to perform mathematical operations like addition, subtraction, multiplication, division, and modulus.

  • + : Addition
  • - : Subtraction
  • * : Multiplication
  • / : Division
  • % : Modulus (remainder of division)

Comparison Operators

Comparison operators are used to compare two values. They return a boolean result (true or false).

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

Logical Operators

Logical operators are used to combine conditional statements. They return a boolean result.

  • && : Logical AND (returns true if both operands are true)
  • || : Logical OR (returns true if at least one operand is true)
  • ! : Logical NOT (inverts the truth value of the operand)

Bitwise Operators

Bitwise operators perform operations on individual bits of a number. They are useful for low-level programming tasks.

  • & : Bitwise AND
  • | : Bitwise OR
  • ^ : Bitwise XOR (exclusive OR)
  • &^ : Bitwise AND NOT
  • << : Left shift
  • >> : Right shift

Examples

Let's explore each type of operator with practical examples.

Arithmetic Operators

Go
1package main
2
3import "fmt"
4
5func main() {
6 a := 10
7 b := 3
8
9 fmt.Println("Addition:", a + b) // Output: Addition: 13
10 fmt.Println("Subtraction:", a - b) // Output: Subtraction: 7
11 fmt.Println("Multiplication:", a * b) // Output: Multiplication: 30
12 fmt.Println("Division:", a / b) // Output: Division: 3
13 fmt.Println("Modulus:", a % b) // Output: Modulus: 1
14}

Comparison Operators

Go
1package main
2
3import "fmt"
4
5func main() {
6 a := 10
7 b := 20
8
9 fmt.Println("Equal to:", a == b) // Output: Equal to: false
10 fmt.Println("Not equal to:", a != b) // Output: Not equal to: true
11 fmt.Println("Less than:", a < b) // Output: Less than: true
12 fmt.Println("Greater than:", a > b) // Output: Greater than: false
13 fmt.Println("Less than or equal to:", a <= b) // Output: Less than or equal to: true
14 fmt.Println("Greater than or equal to:", a >= b) // Output: Greater than or equal to: false
15}

Logical Operators

Go
1package main
2
3import "fmt"
4
5func main() {
6 x := true
7 y := false
8
9 fmt.Println("Logical AND:", x && y) // Output: Logical AND: false
10 fmt.Println("Logical OR:", x || y) // Output: Logical OR: true
11 fmt.Println("Logical NOT:", !x) // Output: Logical NOT: false
12}

Bitwise Operators

Go
1package main
2
3import "fmt"
4
5func main() {
6 a := 10 // Binary: 1010
7 b := 6 // Binary: 0110
8
9 fmt.Println("Bitwise AND:", a & b) // Output: Bitwise AND: 2 (Binary: 0010)
10 fmt.Println("Bitwise OR:", a | b) // Output: Bitwise OR: 14 (Binary: 1110)
11 fmt.Println("Bitwise XOR:", a ^ b) // Output: Bitwise XOR: 12 (Binary: 1100)
12 fmt.Println("Bitwise AND NOT:", a &^ b) // Output: Bitwise AND NOT: 8 (Binary: 1000)
13 fmt.Println("Left shift:", a << 1) // Output: Left shift: 20 (Binary: 10100)
14 fmt.Println("Right shift:", a >> 1) // Output: Right shift: 5 (Binary: 0101)
15}

What's Next?

Now that you have a good understanding of operators in Go, the next step is to learn about control structures such as loops and conditionals. These will allow you to write more complex programs by controlling the flow of execution based on conditions.

Stay tuned for our next tutorial on "Control Structures"!


PreviousData TypesNext Control Structures (if, else, switch)

Recommended Gear

Data TypesControl Structures (if, else, switch)