Can any one tell me why the out put is "1 40 0" and not "1 40 1"
cheers!Code:main()
{
int x;
printf("%d%d%d",x<=50,x=40,x>=10);
getch();
}
Printable View
Can any one tell me why the out put is "1 40 0" and not "1 40 1"
cheers!Code:main()
{
int x;
printf("%d%d%d",x<=50,x=40,x>=10);
getch();
}
It's undefined.
The standard emposes no order of which arguments are evaulated, that's up to the compiler (and optimization it might do*).
* Which may change the result when optimizations are on or off for example.
You have not initialized x so it's value is undefined. Also it is undefined what the order of argument evaluation is, so you do not know whether or not x=40 happens before x>=10, and obviously in this case it doesn't.
Why would you be doing something like this?
The obvious "fix" is;
Code:int main(void)
{
int x = 2;
int a, b;
a = (x <= 50);
x = 40;
b = (x >= 10);
printf("%d %d %d\n", a, x, b);
return 0;
}
it completely depends on the compiler used.also as x is undefined , any garbage value is taken up and according to this value & the order of argument evaluation the compiler produces the output.Quote:
Can any one tell me why the out put is "1 40 0" and not "1 40 1"