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.
Output:

Example code:

Select To use this code as it is.. select and copy paste this code into code.cpp file :)



  1. #include<iostream.h>
  2. #include<conio.h>
  3. void main()
  4. {
  5. clrscr();
  6. int a,b;
  7. a=1;
  8. cout<<a<<endl;
  9. cout<<a++<<endl;
  10. cout<<a<<endl<<endl;
  11. b=5;
  12. cout<<b<<endl;
  13. cout<<++b<<endl;
  14. cout<<b<<endl;
  15. getch();
  16. }

Check out this stream