Sequence points at ;
What you'll learn: How the semicolon acts as a "checkpoint" that ensures all changes to variables are finalized before the next line of code begins.
The "Save Point" in your code
In C, many operations have "side effects." For example, when you use the increment operator (++), the value of a variable changes. However, inside a complex line of code, the computer might be juggling several tasks at once. It needs a clear signal to stop, catch its breath, and make sure every variable is updated correctly.
This signal is the sequence point, and the most common one you will encounter is the semicolon (;).
Think of a semicolon like a "Save Point" in a video game. You might run around, collect coins, and take damage during a level, but your progress isn't officially locked in until you hit that checkpoint. In C, the semicolon guarantees that all the "work" (side effects) described in that statement is completely finished before the program moves to the next instruction.
Watching the checkpoint in action
Consider how the computer processes a simple increment and assignment. Without sequence points, the order of events could get messy.
#include <stdio.h>
int main() {
int cookies = 5;
// The semicolon below is a sequence point.
cookies++;
// Because of the semicolon above, C guarantees that
// 'cookies' is exactly 6 before this next line starts.
printf("I have %d cookies.\n", cookies);
return 0;
}
In the example above, cookies++ has the side effect of adding one to the variable. The semicolon acts as a wall. It tells the CPU: "Do not even look at the printf function until you have finished updating the memory for cookies."
Why this matters
Sequence points prevent "temporal overlap." If you try to do too much in one statement—like changing a variable and using it multiple times before a semicolon appears—you can run into "undefined behavior." This is because you are asking the computer to use a value before it has reached a official checkpoint to save its progress.
By respecting the semicolon, you ensure that your program's state is stable and predictable every time you move to a new line.
Key takeaway
The semicolon is a sequence point that forces the computer to finalize all variable changes before moving past it.