ambigious behaviour of increment operator in print

2019-09-22 06:14发布

问题:

Possible Duplicate:
Undefined Behavior and Sequence Points

the output of the programme

#include<stdio.h>
main()
{

 int i = 10;
 printf("%d %d %d\n", ++i, i++, ++i);

}

is 13 11 13. Can someone please explain this ?

回答1:

It's the oldest question ever. Why do people find this so fascinating?

This is undefined behavior; you're relying on side-effects without a sequence point between modifications.



标签: c printf