Wednesday, April 29, 2009

What is the difference between a++ and ++a?

The difference between a++ and ++a, is that when we use a++ in a program and then the effect would be on the next statement while the ++a, effect is that on the current line not on the next statement. Example code:


Output:


Code:

#include<……>

#include<……>

int main()

{

int c=1;

c=5;

printf("%d\n",c);

printf("%d\n",c++);

printf("%d\n\n",c);

c=10;

printf("%d\n",c);

printf("%d\n",++c);

printf("%d",c);

getch();

}