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.
精彩评论