Certain incremental and decrement statements, such as the following, are so commonly used in C, especially when working with loops, that there is even a shorthand for the shorthand!
i += 1;i -= 1;
Because of their ubiquitousness, there is yet another shorthand notation just for these operations of adding one to or subtracting one from a variable!
Investigate13.4.
Do you remember what the following is shorthand notation for:
i += 1;
In the following video, we’ll take a look at the shorthand notation that shortens the already short compound assignment operators += and +=:
If you cannot see this codecast, please click here.
Check Your UnderstandingCheck Your Understanding
1.
What does the following code print to the screen?
int i = 5;
i++;
printf("%d ", i);
printf("%d ", i++);
printf("%d ", i--);
printf("%d ", --i);