Operator Precedence in C

operator precedence in c

Operator Precedence :

Here, in this page we will discuss about the operator Precedence in C. C provides quite a variety of operators which come in handy to the programmer for the manipulation of variables.Operator Precedence is defined by how two operators are bind together and how they will be evaluated. Operator with more precedence will be evaluated first in an expression.

Operator Precedence

The operators in C are as follows:

  • Arithmetic Operators
  • Relational Operators
  • Bit-wise Operators
  • Logical Operators
  • Assignment Operators
  • Miscellaneous Operators

For example x = 10 – 4 * 2, here the value of x will be 2 not 12 as * (Multiplication) has more precedence over -, so it will be evaluated first which gives 8, then 8 will be subtracted from 10 which gives our final answer 2.

Precedence And Associativity Table :

Operator Precedence in C

Example :

Run
#include <stdio.h>
int main() {
    int a = 10, b = 20, c = 30, d = 60;
    int res;

    //10 + 600
    res = a + b * c;          
    printf("%d\n",res);

    //30 * 30
    res = (a + b) * c;     
    printf("%d\n",res);

    //30 * 2        
    res = (a + b) * (d / c);  
    printf("%d",res);
    return 0;
}
Output:

610
900
60

Prime Course Trailer

Related Banners

Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription

Get over 200+ course One Subscription

Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others

Checkout list of all the video courses in PrepInsta Prime Subscription

Checkout list of all the video courses in PrepInsta Prime Subscription