开发者

predict the output

开发者 https://www.devze.com 2023-01-28 08:28 出处:网络
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);
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

精彩评论

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