Professional Documents
Culture Documents
This operator does not make any effect on the operand value, it just returns operands value.
1. #include<stdio.h>
int main()
{
int x, y;
x = 5;
y = x++ / 2;
printf("%d", y);
return 0;
}
Output: 2 (The given expression is:- y=x++ / 2; x++ so post-increment, y=5/2=2. Hence, x=6 and y=2)
2. #include<stdio.h>
int main()
{
int a=4,b,c;
b = --a;
c = a--;
printf("%d %d %d",a,b,c);
return 0;
}
Output: 2 3 3
The first expression is b=–a; so, a becomes 3 (a=3) and b=3. Now, c=a–; so, c=3 and a=2. Finally, a=2, b=3 and
c=3
3. #include<stdio.h>
int main()
{
int a=5;
printf("%d", ++a++);
return 0;
}
4. #include<stdio.h>
int main()
{
int a=3, b=9;
printf("%d ", ++(a*b+1));
return 0;
}
6. #include<stdio.h>
int main()
{
int a=10, b=10,c;
c= ++a+b++;
printf("%d %d %d",a,b,c);
return 0;
}
Output: 11 11 21 First value of a is incremented by 1 then it is added to the value of b. After that value of b is
increase by 1.
7. #include<stdio.h>
int main()
{
int a=2,b=1,c=0;
c = a +++ b;
printf("%d %d %d",a,b,c);
return 0;
}
Output: 3 1 3 The expression c=a+++b; is treated as c=(a++)+b; so, a=3, b=1, c=3
8. #include<stdio.h>
#include<math.h>
int main()
{
int a=2,b;
b=a++ + a-- + ++a + --a;
printf("%d %d",a,b);
}
Output: 2 10