What we see in this little program is demonstration of the pre- and post-increments (and pre-/post-decrement) operators.
Pre-increment: ++a
It increments the value of a, then whatever expression this value is used will have the new value.
With pseudo code:
Type preincrement(Type value)
{
increment(value);
return value;
}
Post-increment: a++
It increments the value of a, but only after its original value was used in the expression.
With pseudo code:
Type postincrement(Type value)
{
Type tmp = value;
increment(value);
return tmp;
}
Example #1
When age = 45,
printf("%d\n", age-- + --age);
- first uses the value of age (45) in the addition and decrements its value (45 - 1 = 44) and the other part of the addition is
- the decremented value of the "new" age (44 - 1 = 43)
Example #2
When age = 43,
printf("%d\n", --age + --age);
- first decreases the value of age (43 - 1 = 42) then adds this to
- the decreased value of the "new" age (42 - 1 = 41).
Example #3
When age = 41,
printf("%d\n", ++age + ++age);
- first increments the value of age (41 + 1 = 42) and adds this to
- the incremented value of the "new" age (42 + 1 = 43)
I hope this help. :)