The statement "when the program is run, it executes the statements one by one" shows that you're fundamentally misunderstanding the C programming language.
The C standard says that the compiled program needs to be executed so that the side effects of the program happen in order as if these statements were executed in the C abstract machine according to the rules of the abstract machine. However assigning a value to a non-volatile
variable does not count as such a side effect, i.e. in your program
c = b;
b = a;
a = c; // notice, it is *c* here
since none of the statements have any visibile side effect the compiler is free to reorganize, interleave and eliminate these statements for as long as it does not change any previous or following side effect or their relative ordering.
In practice any decent compiler will notice that this is a swap operation and it would encode this with one assembler opcode, such as the x86 XCHG
even though the C programming language does not have a swap operation in itself. Or, it could be that these generate zero opcodes and the compiler just remembers that "henceforth b
shall be known as a
and a
as b
."
The only way to actually force the compiler to generate a program that would execute each of these statements strictly sequentially would be if each of the statements touch a variable that is volatile
-qualified, because accessing a volatile
qualified object is considered a side effect.