Operator precedence — full table
5.1.5· Coding › C Programming
Precedence aur associativity ka asli matlab
Full table ko kaise padhein
Table highest precedence (sabse tightly binds, upar) se lowest (sabse loosely binds, neeche) tak jaati hai.
| Lvl | Operators | Description | Assoc |
|---|---|---|---|
| 1 | () [] -> . ++ --(postfix) |
calls, subscript, member, postfix | → L→R |
| 2 | ++ --(prefix) + -(unary) ! ~ *(deref) &(addr) sizeof (type) |
unary | ← R→L |
| 3 | * / % |
multiplicative | L→R |
| 4 | + - |
additive | L→R |
| 5 | << >> |
bit shift | L→R |
| 6 | < <= > >= |
relational | L→R |
| 7 | == != |
equality | L→R |
| 8 | & |
bitwise AND | L→R |
| 9 | ^ |
bitwise XOR | L→R |
| 10 | | |
bitwise OR | L→R |
| 11 | && |
logical AND | L→R |
| 12 | || |
logical OR | L→R |
| 13 | ?: |
ternary conditional | ← R→L |
| 14 | = += -= *= /= %= &= ^= |= <<= >>= |
assignment | ← R→L |
| 15 | , |
comma | L→R |

Scratch se parse tree derive karna
Chalte hain a + b * c - d ki grouping step by step derive karte hain — ise memorise karne ki jagah.
- Operators ko precedence ke hisaab se list karo:
*(lvl 3),+aur-(lvl 4). Yeh step kyun? Hum highest precedence par pehle attack karte hain; yeh innermost group banata hai. - Pehle
*group karo:a + (b*c) - d. Kyun?*dono+aur-se aage hai, toh yehbaurcko kisi se pehle le leta hai. - Ab
+aur-tie karte hain (dono lvl 4) → associativity = L→R use karo: pehle left group karo:(a + (b*c)) - d. Kyun? Left-associative ka matlab hai sabse left wala equal-precedence operator pehle bind karta hai.
Final tree: ((a + (b*c)) - d). Ho gaya — uniquely determined.
Worked examples
Recall Feynman: ek 12-saal ke bachche ko explain karo
Socho kuch bachche ek toy (ek number) ke liye tug-of-war khel rahe hain. Kuch bachche "zyada strong" hote hain (higher precedence) aur toy pehle pakad lete hain. × + se stronger hai. Agar do bachche equally strong hain, toh hum ek rule use karte hain: usually "jo left par hai woh jeetta hai" (left-to-right), lekin kuch jaise "=" ke liye right wala jeetta hai. Bas itna hai — precedence strength hai, associativity left/right tie-breaker hai. Computer in rules ka use karta hai taki har math sentence ka exactly ek hi matlab ho.
Active recall
C mein operator ambiguity resolve karne ke liye kaun se do layers hote hain?
Kya precedence evaluation ka order determine karta hai?
x & 1 == 0 kaise parse hota hai?
x & (1 == 0) ki tarah, kyunki == (lvl 7) & (lvl 8) se outranks karta hai.Assignment operators ki associativity?
a = b = 0 ka matlab hai a = (b = 0).&& ya || mein kaun higher hai?
&& higher hai; a || b && c ka matlab hai a || (b && c).1 << 2 + 3 kaise evaluate hota hai?
1 << (2+3) = 32 ki tarah, kyunki + beats <<.Postfix ++ vs unary -: kaun zyada tightly bind karta hai?
++ (lvl 1) unary - (lvl 2) se tighter bind karta hai, toh -a++ hai -(a++).Ternary ?: ki associativity?
a?b:c?d:e hai a?b:(c?d:e).C mein sabse lowest precedence wala operator kaun sa hai?
,.if (a = 5) ek common bug kyun hai?
= assignment hai (5 return karta hai, truthy), comparison == nahi; precedence ise fix nahi karta — yeh alag operator hai.Connections
- Expressions and Statements in C
- Bitwise Operators
- Logical Operators and Short-circuit Evaluation
- Sequence Points and Undefined Behaviour
- Type Casting and Conversions
- The Ternary Conditional Operator