Search⌘ K
AI Features

Operators

Explore Go's built-in operators to perform arithmetic, logical, and bitwise operations. Understand how to use increment and decrement, operator shortcuts, comparisons, and bit shifting to write efficient and clear Go code within basic constructs and data types.

Introduction

A symbol that is used to perform logical or mathematical tasks is called an operator. Go provides the following built-in operators:

  • Arithmetic operators
  • Logical operators
  • Bitwise operators

Arithmetic operators

The common binary operators +, -, * and / that exist for both integers and floats in Golang are:

  • Addition operator +
  • Subtraction operator -
  • Division operator /
  • Modulus operator %
  • Multiplication operator *

The + operator also exists for strings. The / operator for integers is (floored) integral division. For example, 9/49/4 will give you 22 ...