13 June, 2011

Simple but not Simple!!!!!!

#include
main(){
int x=20;
printf("\n%d\t%d\t%d\n",x,x++,++x);
}

What is the o/p of the above prg and plz explain the logic???

1 comment:

  1. Function parameter evaluation order is unspecified in C/C++. Parameters might be read from right to left or left to right. Throw a dice and check your answer.
    My previous assumption was that function parameters are read from right to left. For this assumption, answer would have been x = 22, x++ = 21 and ++x = 21. But o/p i got is x =22, x++ = 21 and ++x = 22 which is a (headbang) o/p.
    Please refer to the following link and let me know if you understood it completely.

    http://stackoverflow.com/questions/376278/parameter-evaluation-order-before-a-function-calling-in-c

    ReplyDelete