So I was playing around with increments in C and I ran this code
int main() {
int a = 3;
int b = 8;
b = a++;
printf("%d %d",a, b);
return 1;
}
Originally I thought, oh yeah that's easy... So I thought it would print out 3 and 3.
This is because a++ is a post increment, and increments the value after it has been used it the function. Instead the answer is
a=4
b=3
I don't understand how post increment a is adding to a before the function has completed, i.e the printf statement.
Can someone explain why the answer is, what it is.
Thank you
++
woks in pre-and-post – Grijesh Chauhan