Post-Increment : y = a ++
Steps :
- Value of a is assigned to y
- Then value of a is incremented
In Short :
- When Postfix (++/-) is used with a variable in an Expression ,The Expression is evaluated first using the original value of variable and then variable is incremented/decremented by one
- Here a is incremented /decremented after use
Live Example :
#include<stdio.h>void main(){int a,b,x=10,y=10;a = x++;b = ++y;printf("Value of a : %d",a);printf("Value of b : %d",b);}
Output :
Value of a : 10Value of b : 11
Why Output is 10 in case of Post-increment :
- Post (after) , Value of x is first assigned to a
- Then x is Incremented