Operators
There is no operator overloading. When you see an operator in Zig, you know that it is doing something from this table, and nothing else.
Table of Operators
Syntax | Relevant Types | Description | Example |
---|---|---|---|
| Addition.
|
| |
| Wrapping Addition.
|
| |
| Saturating Addition.
|
| |
| Subtraction.
|
| |
| Wrapping Subtraction.
|
| |
| Saturating Subtraction.
|
| |
| Negation.
|
| |
| Wrapping Negation.
|
| |
| Multiplication.
|
| |
| Wrapping Multiplication.
|
| |
| Saturating Multiplication.
|
| |
| Division.
|
| |
| Remainder Division.
|
| |
| Bit Shift Left.
|
| |
| Saturating Bit Shift Left.
|
| |
| Bit Shift Right.
|
| |
| Bitwise AND.
|
| |
| Bitwise OR.
|
| |
| Bitwise XOR.
|
| |
| Bitwise NOT. |
| |
| If a is null , returns b (“default value”), otherwise returns the unwrapped value of a . Note that b may be a value of type noreturn. |
| |
| Equivalent to:
|
| |
| If a is an error , returns b (“default value”), otherwise returns the unwrapped value of a . Note that b may be a value of type noreturn. err is the error and is in scope of the expression b . |
| |
| If a is false , returns false without evaluating b . Otherwise, returns b . |
| |
| If a is true , returns true without evaluating b . Otherwise, returns b . |
| |
| Boolean NOT. |
| |
| Returns true if a and b are equal, otherwise returns false . Invokes Peer Type Resolution for the operands. |
| |
| Returns true if a is null , otherwise returns false . |
| |
| Returns false if a and b are equal, otherwise returns true . Invokes Peer Type Resolution for the operands. |
| |
| Returns true if a is greater than b, otherwise returns false . Invokes Peer Type Resolution for the operands. |
| |
| Returns true if a is greater than or equal to b, otherwise returns false . Invokes Peer Type Resolution for the operands. |
| |
| Returns true if a is less than b, otherwise returns false . Invokes Peer Type Resolution for the operands. |
| |
| Returns true if a is less than or equal to b, otherwise returns false . Invokes Peer Type Resolution for the operands. |
| |
| Array concatenation.
|
| |
| Array multiplication.
|
| |
| Pointer dereference. |
| |
| All types | Address of. |
|
| Merging Error Sets |
|
Precedence
x() x[] x.y x.* x.?
a!b
x{}
!x -x -%x ~x &x ?x
* / % ** *% *| ||
+ - ++ +% -% +| -|
<< >> <<|
& ^ | orelse catch
== != < > <= >=
and
or
= *= *%= *|= /= %= += +%= +|= -= -%= -|= <<= <<|= >>= &= ^= |=