a++ is known as post increment and ++a is known as pre-increment. In C or C++ a++ and ++a keyword is used to increment the value of a by 1. That is when the value of a is 5 after a++ or ++a will increment the value of a to 6.
But there is a difference between these two keywords during execution.
int a = 5;
printf("%d", a++);
This will print 5
int a = 5;
printf("%d",++a);
This will print 6
Post increment (a++) will increment the value of a by one after performing the operation. To understand this we can take the above example. In this example printf("%d", a++); upto the semicolon (;) value of a is 5 after that only value of a will be changed to 6.
But there is a difference between these two keywords during execution.
int a = 5;
printf("%d", a++);
This will print 5
int a = 5;
printf("%d",++a);
This will print 6
How *-)
As the name suggest pre increment (++a) will increment the value first and then only it will perform any of the activity in that line up to semi colon(;).Post increment (a++) will increment the value of a by one after performing the operation. To understand this we can take the above example. In this example printf("%d", a++); upto the semicolon (;) value of a is 5 after that only value of a will be changed to 6.