开发者

predict the output

void call(int x,int开发者_Python百科 y,int z)
{
  printf("%d   %d  %d",x,y,z);
}
int main()
{
  int a=10;
  call(a,a++,++a);
  return 0;
}

this program is giving different output on different compiler and when i compiled it on linux m/c output was quite weird,any reason.


Because the behaviour is undefined. The compiler is allowed to evaluate a, a++ and ++a in any order before passing them to call(). (Technically, because we've invoked undefined behaviour, it actually doesn't have to do anything in particular at this point; it may write whatever code it pleases.) Depending on what order they're evaluated in, the results differ.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜