[go: up one dir, main page]

0% found this document useful (0 votes)
5 views2 pages

C Operator Precedence Associativity

The document outlines the operator precedence and associativity in C programming, detailing the order in which operators are evaluated. It categorizes operators into levels from highest to lowest precedence, explaining their types (unary or binary) and providing tips for their use. Each operator's associativity is also specified, indicating whether they are evaluated from left to right or right to left.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views2 pages

C Operator Precedence Associativity

The document outlines the operator precedence and associativity in C programming, detailing the order in which operators are evaluated. It categorizes operators into levels from highest to lowest precedence, explaining their types (unary or binary) and providing tips for their use. Each operator's associativity is also specified, indicating whether they are evaluated from left to right or right to left.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

C Operator Precedence and

Associativity
Precedence Operators Description Associativity Unary/ Tips
Level Binary

1 (Highest) () [] . -> Function Left to Right Binary Always done


call, array first. () can
subscript, override all
member precedence
access

2 ++ -- Post- Left to Right Unary Use after


(postfix) increment, variable: a+
Post- +, a--
decrement

3 ++ -- + - ! ~ * Unary plus, Right to Left Unary Most


& sizeof minus, common in
logical not, expressions
bitwise not, like -a, !a,
dereference, *ptr
address, size

4 */% Multiply, Left to Right Binary Same as


divide, math rules.
modulo Do these
before + or -

5 +- Addition, Left to Right Binary Done after


subtraction multiplicatio
n

6 << >> Bitwise shift Left to Right Binary Use with


left/right integer bit
manipulatio
n

7 < <= > >= Relational Left to Right Binary Comparison


operators for size

8 == != Equality and Left to Right Binary Always done


inequality after
relational
ops

9 & Bitwise AND Left to Right Binary Not logical


AND! Works
on bits

10 ^ Bitwise XOR Left to Right Binary Toggle bits

11 | Bitwise OR Left to Right Binary Combine


bits

12 && Logical AND Left to Right Binary Both


conditions
must be true

13 || Logical OR Left to Right Binary At least one


must be true

14 ?: Ternary Right to Left Ternary cond ?


conditional true_val :
false_val

15 = += -= *= /= Assignment Right to Left Binary Right side


%= <<= >>= operators evaluated
&= ^= |= first

16 (Lowest) , Comma Left to Right Binary Evaluates


operator expressions
left to right

You might also like