comparsion

answerme's Avatar, Join Date: Dec 2007
Ambitious contributor
main()
{
int x=10 ,y=20,z=5 ,i;
i=x<y<z;
printf("%d",i);
}

output :1
why the output is 1 ,how x ,y ,z are gettting compared
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Just put a brackets and see how its getting evaluated.

Check the output for both the cases below
i=(x<y)<z;
i=x<(y<z);
0
asadullah.ansari's Avatar, Join Date: Jan 2008
TechCake
i=x<y<z
=> i= 10<20<z
=> i= true(1) < 5
=> i= true(1)
=> i=1
This is true If Compiler evaluates from Left to Right if same perority operator are there.