#1 India's Top IT Training Institute

×

About Uncodemy

Know more about who we are and what we stand for.

About Us

About Us

Discover our mission to equip individuals with essential IT skills and industry expertise.

Read More →
UnCodeMy Gallery

UnCodeMy Gallery

Explore highlights from our IT training sessions and success stories.

Read More →
×

Free Resources

Learn, practice and plan your career — bilkul free.

Tutorials

Tutorials

Step-by-step written tutorials to learn any technology at your own pace.

Read More →
Free Counselling

Free Counselling

Book a free video counselling session and pick the right course for you.

Read More →
Online Compiler

Online Compiler

Write, run and test your code online — no setup required.

Read More →

Precedence Table in C Language Explained: Know What Comes First!

🧠 Introduction: Why Operator Precedence Matters

Precedence Table in C Language Explained

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.

🛠️ What is Operator Precedence?

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.

🔄 What is Associativity?

When two operators of the same precedence appear, associativity decides the direction in which they are evaluated:

  • 1. Left-to-right (LTR)
     
  • 2. Right-to-left (RTL)

📋 Precedence Table in C Language Explained

Here’s a simplified and readable operator precedence table (from highest to lowest):

Precedence LevelOperatorsAssociativityDescription
1 (Highest)() [] . ->Left to RightFunction call, array, structure
2++ -- + - ! ~ * &Right to LeftUnary operators
3* / %Left to RightMultiplication, Division, Modulus
4+ -Left to RightAddition, Subtraction
5<< >>Left to RightBitwise shift
6< <= > >=Left to RightRelational
7== !=Left to RightEquality
8&Left to RightBitwise AND
9^Left to RightBitwise XOR
10``Left to Right
11&&Left to RightLogical AND
12` `
13?:Right to LeftTernary conditional
14= += -= *= /= %= etc.Right to LeftAssignment
15 (Lowest),Left to RightComma separator

🧪 Examples to Make It Clear

🧮 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

🛑 Common Mistakes and Misunderstandings

MistakeExplanation
Ignoring parenthesesCan lead to wrong results
Misunderstanding associativityAssignment operators are right-to-left
Assuming logical AND/OR runs before equalityEquality has higher precedence
Mixing pre and post increment++x vs x++ can give different results

✅ Best Practices

  • 1. Use parentheses to make expressions clearer and avoid confusion
     
  • 2. Know that higher precedence doesn't always mean better readability
     
  • 3. Stick to one operation per line when debugging complex logic
     
  • 4. Practice with real-world expressions and see how outputs change

💼 Real-World Use Cases

SituationExample
Grading system(score >= 90) ? 'A' : 'B'
Arithmetic calculatorsvalue = a + b * c
Conditional logicif (age > 18 && income > 30000)
Complex updatesx = y = z = 100

🎓 Learn C Programming with Uncodemy

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

🧰 Course Highlights:

✅ 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.

📌 Summary Table: Key Takeaways

ConceptMeaning
PrecedenceOrder in which operators are evaluated
AssociativityDirection (LTR or RTL) of evaluation
High precedenceExecuted first in expressions
Use of ()Overrides default precedence
AssignmentsRight-to-left associativity

👋 Final Thoughts

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!

Placed Students

Our Clients

Partners

...

Uncodemy Learning Platform

Popular Courses