diff --git a/c-operator-precedence.md b/c-operator-precedence.md new file mode 100644 index 0000000..d7b5ec7 --- /dev/null +++ b/c-operator-precedence.md @@ -0,0 +1,75 @@ +# 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 | ++---------------+---------------+---------------------------------------+-------------------+