BeginnersBook

  • Home
  • Java
    • Java OOPs
    • Java Collections
    • Java Examples
  • C
    • C Examples
  • C++
    • C++ Examples
  • DBMS
  • Computer Network
  • Python
    • Python Examples
  • More…
    • jQuery
    • Kotlin
    • WordPress
    • SEO
    • JSON
    • JSP
    • JSTL
    • Servlet
    • MongoDB
    • XML
    • Perl

Operator precedence and Associativity in C programming language

Last Updated: September 23, 2017 by Chaitanya Singh | Filed Under: c-programming

In this guide, we will learn operator precedence and associativity in C Programming.

Operator Precedence in C
Operator precedence determines which operator is evaluated first when an expression has more than one operators. For example 100-2*30 would yield 40, because it is evaluated as 100 – (2*30) and not (100-2)*30. The reason is that multiplication * has higher precedence than subtraction(-).

Associativity in C
Associativity is used when there are two or more operators of same precedence is present in an expression. For example multiplication and division arithmetic operators have same precedence, lets say we have an expression 5*2/10, this expression would be evaluated as (5*2)/10 because the associativity is left to right for these operators. Similarly 20/2*5 would be calculated as (20*2)/5.

Operator precedence and Associativity Table in C Programming

Description Operator Associativity
Function expression

( )

Left to Right
Array Expression

[]

Left to Right
Structure operators

->

Left to Right
Unary minus

–

Right to Left
Increment & Decrement

—  ++

Right to Left
One’s compliment

~

Right to Left
Pointer Operators

& *

Right to Left
Type cast

(data type)

Right to Left
size of operator

sizeof

Right to Left
Left and Right Shift

>>  <<

Arithmetic Operators

Multiplication operator, Divide by, Modulus

*,  /,  %

Left to Right
Add, Substract

+,  –

Left to Right

Relational Operators

Less Than

<

Left to Right
Greater than

>

Left to Right
Less than equal to

<=

Left to Right
Greater than equal to

>=

Left to Right
Equal to

==

Left to Right
Not equal

!=

Left to Right

Logical Operators

AND

&&

Left to Right
OR

||

Left to Right
NOT

!

Right to Left

Bitwise Operators

AND

&

Left to Right
Exclusive OR

^

Left to Right
Inclusive OR

|

Left to Right

Assignment Operators

=

Right to Left

*=

Right to Left

/=

Right to Left

%=

Right to Left

+=

Right to Left

-=

Right to Left

&=

Right to Left

^=

Right to Left

|=

Right to Left

<<=

Right to Left

>>=

Right to Left

Other Operators

Comma

,

Right to Left
Conditional Operator

?:

Right to Left
❮ PreviousNext ❯

Top Related Articles:

  1. Unary Operator in C with Examples
  2. Arithmetic Operators in C with Examples
  3. Conditional (Ternary) Operator in C with Examples
  4. Assignment Operators in C with Examples
  5. Pointers in C Programming with examples

About the Author

I have 15 years of experience in the IT industry, working with renowned multinational corporations. Additionally, I have dedicated over a decade to teaching, allowing me to refine my skills in delivering information in a simple and easily understandable manner.

– Chaitanya

Comments

  1. shruti says

    September 22, 2015 at 6:44 AM

    The explaination is easy to understand and to the point.Thanx, it helped me a lot:)

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

C Programming Tutorial

  • C Tutorial
  • History of C
  • Features of C
  • Turbo C++ installation
  • First C Program
  • printf scanf
  • Variables in C
  • Data Types in C
  • C - Keywords
  • C Identifiers
  • C Comments
  • Operator precedence
  • C - if statement
  • C - if..else
  • C - for loop
  • C - while loop
  • C - do while loop
  • C - continue
  • C - break statement
  • C - switch..case
  • C - goto statement
  • C - Arrays
  • 2 D array
  • C - String
  • C - functions
  • Function call by reference
  • Function call by value
  • Array to function
  • C - Structures
  • C - Pointers
  • Pointer to Pointer
  • Pointers to functions
  • C - function pointers
  • Pointer & Array
  • C - File I/O
  • C Programming Examples

Copyright © 2012 – 2025 BeginnersBook . Privacy Policy . Sitemap