Is this undefined C behaviour?

前端 未结 8 997
我在风中等你
我在风中等你 2020-11-29 06:26

Our class was asked this question by the C programming prof:

You are given the code:

int x=1;
printf(\"%d\",++x,x+1);

What output w

8条回答
  •  星月不相逢
    2020-11-29 06:51

    The points made about undefined behavior are correct, but there is one additional wrinkle: printf may fail. It's doing file IO; there are any number of reasons it could fail, and it's impossible to eliminate them without knowing the complete program and the context in which it will be executed.

提交回复
热议问题