Go: Operators

See Operator precedence for evaluation order.

Arithmetic

Operator Name Types
+ sum integers, floats, complex values, strings
- difference integers, floats, complex values
* product integers, floats, complex values
/ quotient integers, floats, complex values
% remainder integers
& bitwise AND integers
| bitwise OR integers
^ bitwise XOR integers
&^ bit clear (AND NOT) integers
<< left shift integer << unsigned integer
>> right shift integer >> unsigned integer

See Arithmetic operators in the Go language specification for complete definitions of the shift, quotient and remainder operators, integer overflow, and floating point behavior.

Comparison

Comparison operators compare two operands and yield an untyped boolean value.

Operator Name Types
== equal comparable
!= not equal comparable
< less integers, floats, strings
<= less or equal integers, floats, strings
> greater integers, floats, strings
>= greater or equal integers, floats, strings

Logical

Logical operators apply to boolean values. The right operand is evaluated conditionally.

Operator Name Description
&& conditional AND p && q denotes "if p then q else false"
|| conditional OR p || q denotes "if p then true else q"
! NOT !p denotes "not p"

Others

Operator Name Description
& address of &x generates a pointer to x
* pointer indirection *x denotes the variable pointed to by x
<- receive <-ch is the value received from channel ch

Comments

Be the first to comment!