Pre-Increment : y = ++ivar  Steps :

  1. Value of ivar is incremented 
  2. Then value of ivar is assigned to y
In Short :
  • When Prefix (++/--) is used with a variable in an Expression .
  • The variable is incremented/decremented by one  then  Expression is evaluated using the original value of variable
  • Here a is incremented /decremented before use
Live Example :


#include<stdio.h>
void main()
{
int a,b,x=10,y=10;
a = x++;
b = ++y;                    // Pre-Incremented
printf("Value of a : %d",a);
printf("Value of b : %d",b);
}
Output :
Value of a : 10
Value of b : 11
Why Output is 11 in case of Pre-increment : 
  1. Pre (before) , Value of y is first incremented i.e y = 11
  2. Then y is assigned to b


Tags / Keywords : | , , ,

0 comments

Post a Comment

Your Feedback :This is Growing Site and Your Feedback is important for Us to improve the Site performance & Quality of Content.Feel Free to contact and Please Provide Name & Contact Email