Go Operators

Go operators

Operators

x + y       addition (also used for string concatenation)
x - y       subtraction
x * y       multiplication
x / y       division
x % y       remainder
x & y       bitwise AND
x | y       bitwise OR
x ^ y       bitwise XOR
x &^ y      x AND (NOT y)
x << y      shift x left by y bits
x >> y      shift x right by y bits
x = y       assign y to x
x := y      assign y to x (can be used for initialization)
x++         equivalent to x = x + 1
x--         equivalent to x = x - 1
x += y      equivalent to x = x + y
x -= y      equivalent to x = x - y
x *= y      equivalent to x = x * y
x /= y      equivalent to x = x / y
x %= y      equivalent to x = x % y
x &= y      equivalent to x = x & y
x |= y      equivalent to x = x | y
x ^= y      equivalent to x = x ^ y
x &^= y     equivalent to x = x &^ y
x <<= y     equivalent to x = x << y
x >>= y     equivalent to x = x >> y
x && y      logical AND
x || y      logical OR
!x          false if x is true, true if x is false
x == y      true if x and y are equal
x != y      true if x and y are not equal
x < y       true if x is less than y
x <= y      true if x is less than or equal to y
x > y       true if x is greater than y
x >= y      true if x is greater than or equal to y
ch <- x     send x to channel ch
x = <- ch   receive from channel ch into x