Precedence

It dictates the order of evaluation of operators in an expression.

Associativity

If two operators of same precedence (priority) is present in an expression, Associativity of operators indicate the order in which they execute.

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
Category Operator Associativity
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

#1 : Find the o/p of the below program.


	#include <stdio.h>
	
	int main(){
		int a = 4;
		printf("\n %d", 10 + a++);
		printf("\n %d", 10 + ++a);
		return 0;
	}
						

Output:



 14
 16
						

#2 : Find the o/p of the below program.


	#include <stdio.h>
	
	int main(){
		int a=4, b=5, c=6;
		a = b == c;
		printf("\n a = %d",a);
		return 0;
	}
						

Output:



 a = 0
						

#3 : Find the o/p of the below program.


	#include <stdio.h>
	
	int main(){
		int a=1, b=2, c=3, d=4, e=5, res;
		res = a + b/c -d * e;
		printf("\n Result = %d", res);
		res = (a + b) / c - d * e;
		printf("\n Result = %d", res);
		res = a + (b/(c-d)) * e;
		printf("\n Result = %d",res);
		return 0;
	}
						

Output:



 Result = -19
 Result = -19
 Result = -9
						

#4 : Find the o/p of the below program.


	#include <stdio.h>
	
	int main(){
		int a=1,b=2,c=3;
		printf("++a - b++ - --c - --c + %d \n",a);
		printf("--a + %d \n",++b - c + --a);
		return 0;
	}
						

Output:


++a - b++ - --c - --c + 1
--a + 0
						

#5 : Find the o/p of the below program.


	#include <stdio.h>
	
	int main(){
		int a=100,b=3;
		float c;
		c = a/b;
		printf("\n c = %f",c);
		c=(a*++b)/3.0;
		printf("\n c = %d",(int)c);
		return 0;
	}
						

Output:



c = 33.000000
c = 133
						

#6 : Find the o/p of the below program.


	#include <stdio.h>
	
	int main(){
		int a=1,b=3,c=6,ans=0;
		printf("\n %d", (a>b && a<c));
		ans *= --b + ++a*c++; 
		printf("\n %d",ans);
		printf("\n c = %d",(b>10 || (b + a)>0 || a != b));
		return 0;
	}
						

Output:



 0
 0
 c = 1
						

#7 : Find the o/p of the below program.


	#include <stdio.h>
	
	int main(){
		int x=2,y=4,z=1,ans;
		z += y++ - ++x; 
		printf("\n %d", z);
		ans = ++x + ++x * --x * --z;
		printf("\n %d",ans);
		ans = x+++y;
		printf("\n %d %d %d %d",x,y,z,ans);
		return 0;
	}
						

Output:



 2
 24
 5 5 1 9
						

#8 : Find the o/p of the below program.


	#include <stdio.h>
	
	int main(){
		int x=4;
		char ch = 'E'; 
		printf("\n %d", ch+x);
		ch += x*8;
		printf("\n %c",ch);
		return 0;
	}
						

Output:



 73
 e