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.
Output:
Example code:
- #include<iostream.h>
- #include<conio.h>
- void main()
- {
- clrscr();
- int a,b;
- a=1;
- cout<<a<<endl;
- cout<<a++<<endl;
- cout<<a<<endl<<endl;
- b=5;
- cout<<b<<endl;
- cout<<++b<<endl;
- cout<<b<<endl;
- getch();
- }