operators

operators (ALL INCLUDE PRECEDENCE AND ASSOCIATION)

It is essential to master these.

arithmetic operator

assignment operator

increment and decrement operator

relational operators precedence and association

relational operators (<, >, <=, >=) have a lower precedence to arithmetic and are left associative. WARN: i < j < k:= (i < j) < k where (i < j) == 1 || 0; What you may want is i < j && j < k

equality operators precedence and association

== and != have a lower precedence than relational operators and are left associative.

logical operations and short-circuiting

! has the same precedence as unary plus and minus, and is right associative. Logical operations && and || have lower precedence to than equality are left associative.

Short-circuiting := if with the first operand we know the outcome of the expression, then we do not compute the full expression. e.g. (i != 0) && (j / i > 0) when i is equal to zero the program knows that the expression will fail and therefore not compute the second expression.

conditional operator

expr1 ? expr2 : expr3 :~ if expr1 then expr2 else expr3

comma operator

Allows us to execute multiple statements at once. for example in for_loop, in the first and third expressions It is left associative and has the lowest precedence of all operators. The first expression should have a side effect, otherwise is it pointless.

sizeof

address operator

&:= the address of a variable in memory. Allows you to assign the address of an lvalue to a pointer.

Indirection operator

*:= the value of the variable at the address. The pointer now becomes an alias for the variable. Also known as dereferencing.

left and right bitshift operator

<< shifts the bits to the left. & bitwise AND | bitwise inclusive OR ^ bitwise XOR (exclusive OR) << left shift >> right shift ~ bitwise NOT (ones’ complement) (unary)

the right arrow selection operator (->)

standard

gold

backlinks