What does the rule about sequence points say about the following code?
int main(void) {
int i = 5;
printf("%d", ++i, i); /* Statement 1 */
}
There is just one %d. I am confused because I am getting 6 as output in compilers GCC, Turbo C++ and Visual C++. Is the behavior well defined or what?
This is related to my last question.
It’s undefined because of 2 reasons:
The value of
iis twice used without an intervening sequence point (the comma in argument lists is not the comma operator and does not introduce a sequence point).You’re calling a variadic function without a prototype in scope.
The number of arguments passed toprintf()are not compatible with the format string.the default output stream is usually line buffered. Without a'\n'there is no guarantee the output will be effectively output.