Files
collection/c-operator-precedence.md
2026-06-15 14:44:54 +02:00

6.7 KiB

C operator precedence

+---------------+---------------+---------------------------------------+-------------------+ | piority | operator | description | associativity | +==============:+:==============+:======================================+:==================+ | 1 | ++, -- | postfix/suffix increment and | left to right | | | | decrement | | | +---------------+---------------------------------------+ | | | () | function call | | | +---------------+---------------------------------------+ | | | [] | array indexing/subscripting | | | +---------------+---------------------------------------+ | | | . | member access (struct or union) | | | +---------------+---------------------------------------+ | | | -> | dereferencing member access | | | | | (struct or union) | | | +---------------+---------------------------------------+ | | | (type){list}| dereferencing member access | | | | | (struct or union) | | +---------------+---------------+---------------------------------------+-------------------+ | 2 | ++, -- | prefix increment and decrement | right to left | | +---------------+---------------------------------------+ | | | +, - | unary plus and minus (sign) | | | +---------------+---------------------------------------+ | | | !, ~ | logical and bitwise NOT | | | +---------------+---------------------------------------+ | | | (type) | type cast | | | +---------------+---------------------------------------+ | | | * | dereferencing (indirection) | | | +---------------+---------------------------------------+ | | | & | referencing (get address of) | | | +---------------+---------------------------------------+ | | | sizeof | size of (builtin) | | | +---------------+---------------------------------------+ | | | _Alignof, | alignment requirement (C11 & C23 | | | | alignof | respectively) | | +---------------+---------------+---------------------------------------+-------------------+ | 3 | *, /, % | multiplication, division and modulo | left to right | +---------------+---------------+---------------------------------------+-------------------+ | 4 | +, - | addition and subtractionion | left to right | +---------------+---------------+---------------------------------------+-------------------+ | 5 | <<, >> | bitwise left and right shift | left to right | +---------------+---------------+---------------------------------------+-------------------+ | 6 | <, <=, | less than, less or equal, | left to right | | | >, >= | greater than and greater or euqal | | +---------------+---------------+---------------------------------------+-------------------+ | 7 | ==, != | equals and unequals | left to right | +---------------+---------------+---------------------------------------+-------------------+ | 8 | & | bitwise AND | left to right | +---------------+---------------+---------------------------------------+-------------------+ | 9 | ^ | bitwise XOR (exclusive or) | left to right | +---------------+---------------+---------------------------------------+-------------------+ | 10 | | | bitwise OR (inclusive or) | left to right | +---------------+---------------+---------------------------------------+-------------------+ | 11 | && | logical AND | left to right | +---------------+---------------+---------------------------------------+-------------------+ | 12 | || | bitwise OR | left to right | +---------------+---------------+---------------------------------------+-------------------+ | 13 | ?: | ternary conditional (inline if) | right to left | +---------------+---------------+---------------------------------------+-------------------+ | 14 | = | simple assignment | right to left | | +---------------+---------------------------------------+ | | | +=, -= | assignment by sum and difference | | | +---------------+---------------------------------------+ | | | *=, /=, | simple assignment product, quotient | | | | %= | and remainder | | | +---------------+---------------------------------------+ | | | <<=, >>= | assignment by bitwise left or right | | | | | shift | | | +---------------+---------------------------------------+ | | | &=, ^=, | assignment by bitwise AND, XOR | | | | |= | and OR | | +---------------+---------------+---------------------------------------+-------------------+ | 15 | , | comma to separate entries in a list | left to right | +---------------+---------------+---------------------------------------+-------------------+