C Operator Precedence

Beginner
6 min read
Updated: Nov 2026
1 example

What Is Operator Precedence?

Precedence says which operator binds tighter (* before +). Associativity breaks ties between equal precedence: most binary operators go left to right, while assignment, unary operators, and ?: go right to left. When in doubt, use parentheses.

Remember
highest   () [] -> .  postfix ++ --
          ! ~ unary+ unary- ++ -- * & sizeof casts
          * / %      + -      << >>
          < <= > >=  == !=
          &  ^  |  &&  ||  ?:
lowest    = += -= ...   ,

Cheat Sheet

Keep these facts handy while you work with Operator Precedence in C.

TopicDetail
Arithmetic first2 + 3 * 4 is 14
Left to right10 - 4 - 3 is 3
Right to lefta = b = 7 assigns 7 to both
ParenthesesAlways win

C Examples

Compile each example with gcc file.c -std=c11 -Wall -o out. Next: Control Statements.

Example 1 — Precedence and the bitwise trap

== binds tighter than &, which surprises many beginners.

C
#include <stdio.h>

int main(void) {
    int r1 = 2 + 3 * 4;
    int r2 = (2 + 3) * 4;
    int r3 = 10 - 4 - 3;
    int a, b;
    a = b = 7;

    int flags = 6;
    int wrong = flags & 4 == 4;
    int right = (flags & 4) == 4;

    printf("%d %d %d\n", r1, r2, r3);
    printf("a=%d b=%d\n", a, b);
    printf("wrong=%d right=%d\n", wrong, right);
    return 0;
}

How It Works

  1. * runs before +; parentheses override that.
  2. - is left associative: (10 - 4) - 3.
  3. flags & 4 == 4 is flags & (4 == 4) = 6 & 1 = 0.
  4. Parentheses make the intended (flags & 4) == 4 evaluate to 1.

Edge Cases & Pitfalls

Check these before relying on Operator Precedence in real programs.

bit

Bitwise vs comparison

Always parenthesize bit tests: (x & MASK) == MASK.

mix

Mixing && and ||

a || b && c runs && first. Add parentheses to show intent.

Key Takeaways

  • Remember: multiply before add, compare before bitwise.
  • Ties: associativity decides.
  • Clarity: parentheses beat memorization.

One line: Precedence says which operator binds tighter (* before +).

Frequently Asked Questions

&& has higher precedence than ||, so a || b && c means a || (b && c).
Know the basics (arithmetic, comparison, logical). Use parentheses for everything else, including bitwise tests and mixed && / ||.
Continue with "C Control Statements" next. C tutorial: learn how if, if-else, else-if, nested if, switch, break, continue, and goto control program... The C Operators hub lists every topic in order.

Next: Control Statements

C tutorial: learn how if, if-else, else-if, nested if, switch, break, continue, and goto control program...

Continue →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

12 people found this page helpful