[Solved] Semicolon and Comma in C [closed]


It is because the comma is an operator in C. According to the second edition of The C Programming language:

A pair of expressions separated by a comma is evaluated left to right, and the type and value of the result are the type and value of the right operand.

Be aware though, that it also says:

The commas that separate function arguments, variables in declarations etc., are not comma operators, and do not guarantee left to right evaluation.

A common example of forgetting this is explained here.

So both programs are correct (though only in the second one the inverted value of i is printed).

solved Semicolon and Comma in C [closed]