🧠 Introduction: Why Operator Precedence Matters

Imagine you’re solving this in math:
CopyEdit
3 + 5 * 2
Do you add first or multiply?
You multiply first, right? That’s because multiplication has higher precedence than addition.
The same idea applies in C programming!
When you use multiple operators in a single expression, C decides the order of execution based on operator precedence and associativity. That’s where the precedence table in C language comes in.
Let’s break it down and make operator precedence easy to understand.
In C, operator precedence determines which operator is evaluated first in an expression that contains more than one operator.
Example:
c
CopyEdit
int result = 10 + 5 * 2;
Here, multiplication happens before addition. So:
CopyEdit
5 * 2 = 10
10 + 10 = 20
Without proper understanding, it’s easy to get confused and write code that gives unexpected results.
When two operators of the same precedence appear, associativity decides the direction in which they are evaluated:
Here’s a simplified and readable operator precedence table (from highest to lowest):
| Precedence Level | Operators | Associativity | Description |
| 1 (Highest) | () [] . -> | Left to Right | Function call, array, structure |
| 2 | ++ -- + - ! ~ * & | Right to Left | Unary operators |
| 3 | * / % | Left to Right | Multiplication, Division, Modulus |
| 4 | + - | Left to Right | Addition, Subtraction |
| 5 | << >> | Left to Right | Bitwise shift |
| 6 | < <= > >= | Left to Right | Relational |
| 7 | == != | Left to Right | Equality |
| 8 | & | Left to Right | Bitwise AND |
| 9 | ^ | Left to Right | Bitwise XOR |
| 10 | ` | ` | Left to Right |
| 11 | && | Left to Right | Logical AND |
| 12 | ` | ` | |
| 13 | ?: | Right to Left | Ternary conditional |
| 14 | = += -= *= /= %= etc. | Right to Left | Assignment |
| 15 (Lowest) | , | Left to Right | Comma separator |
🧮 Example 1:
c
CopyEdit
int a = 5 + 2 * 3;
Multiplication first, then addition:
CopyEdit
2 * 3 = 6
5 + 6 = 11
Result: a = 11
🧮 Example 2:
c
CopyEdit
Copy Code
int a = 5, b = 2; int c = a > b && a != b; > and != are relational operators && is a logical operator
Relational operators have higher precedence, so they are evaluated first.
yaml
CopyEdit
Copy Code
5 > 2 → true (1) 5 != 2 → true (1) 1 && 1 → true (1) Result: c = 1
🧮 Example 3 (Associativity):
c
CopyEdit
Copy Code
int x = 5; int y = x = 10; Here = is right-to-left associative, so: ini CopyEdit x = 10 → 10 y = 10
| Mistake | Explanation |
| Ignoring parentheses | Can lead to wrong results |
| Misunderstanding associativity | Assignment operators are right-to-left |
| Assuming logical AND/OR runs before equality | Equality has higher precedence |
| Mixing pre and post increment | ++x vs x++ can give different results |
| Situation | Example |
| Grading system | (score >= 90) ? 'A' : 'B' |
| Arithmetic calculators | value = a + b * c |
| Conditional logic | if (age > 18 && income > 30000) |
| Complex updates | x = y = z = 100 |
If you're serious about mastering C, especially tricky parts like operator precedence, pointers, and memory management, check out:
👉 Uncodemy’s C Programming Course in Noida
✅ Live interactive classes
✅ Practical coding sessions
✅ Doubt-clearing & projects
✅ Certification + placement support
Whether you’re preparing for college, internships, or job interviews—this course has what you need.
| Concept | Meaning |
| Precedence | Order in which operators are evaluated |
| Associativity | Direction (LTR or RTL) of evaluation |
| High precedence | Executed first in expressions |
| Use of () | Overrides default precedence |
| Assignments | Right-to-left associativity |
Understanding the precedence table in C language is key to writing bug-free and logical code. It helps you predict how complex expressions will be evaluated and ensures your programs behave exactly as you intend.
So next time you're writing a formula or condition in C, don’t just rely on guesswork—use precedence and associativity wisely.
And if you’d like expert guidance, doubt support, and live projects—join Uncodemy’s C programming course and level up your skills!
Personalized learning paths with interactive materials and progress tracking for optimal learning experience.
Explore LMSCreate professional, ATS-optimized resumes tailored for tech roles with intelligent suggestions.
Build ResumeDetailed analysis of how your resume performs in Applicant Tracking Systems with actionable insights.
Check ResumeAI analyzes your code for efficiency, best practices, and bugs with instant feedback.
Try Code ReviewPractice coding in 20+ languages with our cloud-based compiler that works on any device.
Start Coding
TRENDING
BESTSELLER
BESTSELLER
TRENDING
HOT
BESTSELLER
HOT
BESTSELLER
BESTSELLER
HOT
POPULAR