0
What is the difference between post increment and pre increment in C programming ??
3 Respuestas
+ 1
Try the C++ course.
It reviews post and prefix
https://www.sololearn.com/Course/CPlusPlus/?ref=app
0
Post Increment:
a = 10;
b = 2;
c = b + a++;
printf("c = %d", c);
printf("\na = %d",a);
Output:
c = 13
a = 11
As you just saw in post increment the old value of variable 'a' is considered and after the value of 'c' is stored, then 'a' is incremented.
Pre Increment:
a = 10;
b = 2;
c = b + ++a;
printf("c = %d", c);
printf("\na = %d",a);
Output:
c = 14
a = 11
Here, the value of 'a' was incremented already while the operation was performed.
So, Post Increment first stores the value in temporary buffer then increments it, while Pre Increment increments it then returns it.