Why is i++ and ++i same in the following code?
#include <stdio.h>
int main()
{
int i=5;
while(1)
{
i++; /*replacing i++ by ++i also gives 6*/
printf("%d",i);
break;
}
return 0;
}
The output is 6. I learnt that the increment operator i++ has its value the current value of i and causes the stored value of i to be incremented.But i's value is displayed as 6 though the current value of i is 5. Replacing i++ by ++i also gives the same value 6. Why is i++ and ++i same in this case and why output is 6 though initial value is 5.