0% found this document useful (0 votes)
45 views

Operators Precedence in C

Operator precedence in C determines the order that terms in an expression are evaluated. Multiplication and division have higher precedence than addition and subtraction. For example, in the expression "x = 7 + 3 * 2", x is assigned 13, not 20, because * has higher precedence than + so 3 * 2 is evaluated first. Operators with the highest precedence appear at the top of the precedence table and are evaluated first within an expression.

Uploaded by

Alankrit Singh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views

Operators Precedence in C

Operator precedence in C determines the order that terms in an expression are evaluated. Multiplication and division have higher precedence than addition and subtraction. For example, in the expression "x = 7 + 3 * 2", x is assigned 13, not 20, because * has higher precedence than + so 3 * 2 is evaluated first. Operators with the highest precedence appear at the top of the precedence table and are evaluated first within an expression.

Uploaded by

Alankrit Singh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

11/3/22, 9:20 PM Operators Precedence in C

Operators Precedence in C

Operator precedence determines the grouping of terms in an expression and decides how an
expression is evaluated. Certain operators have higher precedence than others; for example, the
multiplication operator has a higher precedence than the addition operator.

For example, x = 7 + 3 * 2; here, x is assigned 13, not 20 because operator * has a higher
precedence than +, so it first gets multiplied with 3*2 and then adds into 7.

Here, operators with the highest precedence appear at the top of the table, those with the lowest
appear at the bottom. Within an expression, higher precedence operators will be evaluated first.

Category Operator Associativity

Postfix () [] -> . ++ - - Left to right

Unary + - ! ~ ++ - - (type)* & sizeof Right to left

Multiplicative */% Left to right

Additive +- Left to right

Shift << >> Left to right

Relational < <= > >= Left to right

Equality == != Left to right

Bitwise AND & Left to right

Bitwise XOR ^ Left to right

Bitwise OR | Left to right

Logical AND && Left to right

Logical OR || Left to right

Conditional ?: Right to left

Assignment = += -= *= /= %=>>= <<= &= ^= |= Right to left

Comma , Left to right

Example
https://www.tutorialspoint.com/cprogramming/c_operators_precedence.htm 1/2
11/3/22, 9:20 PM Operators Precedence in C

Try the following example to understand operator precedence in C −

 Live Demo
#include <stdio.h>

main() {

int a = 20;

int b = 10;

int c = 15;

int d = 5;

int e;

e = (a + b) * c / d; // ( 30 * 15 ) / 5

printf("Value of (a + b) * c / d is : %d\n", e );

e = ((a + b) * c) / d; // (30 * 15 ) / 5

printf("Value of ((a + b) * c) / d is : %d\n" , e );

e = (a + b) * (c / d); // (30) * (15/5)

printf("Value of (a + b) * (c / d) is : %d\n", e );

e = a + (b * c) / d; // 20 + (150/5)

printf("Value of a + (b * c) / d is : %d\n" , e );

return 0;

When you compile and execute the above program, it produces the following result −

Value of (a + b) * c / d is : 90

Value of ((a + b) * c) / d is : 90

Value of (a + b) * (c / d) is : 90

Value of a + (b * c) / d is : 50

https://www.tutorialspoint.com/cprogramming/c_operators_precedence.htm 2/2

You might also like