0

What should be the output of this code & why?

int x = 10, y = 20, z = 5, i; i = x < y < z; printf("%d\n", i); Isn’t it compiler dependent?

25th Apr 2020, 11:16 AM
Ashfaq Reshad
Ashfaq Reshad - avatar
3 ответов
+ 5
No, it is not compiler dependent. According to C standard operator < shall yield 1 if its left operand is less than the right one, or 0 otherwise (when its value is used). You can rewtite int x = 10, y = 20, z = 5, i; i = x < y < z; as i = 10 < 20 < 5 operator < is executed left to right: i = (10<20) < 5 so 10 < 20 will be evaluated first. As 10 < 20 is true, it is converted to integer 1 for the next comparision: i = 1 < 5 which is also true, so result will be 1
25th Apr 2020, 11:45 AM
andriy kan
andriy kan - avatar
0
Thanks❤ @andriy kan
25th Apr 2020, 11:51 AM
Ashfaq Reshad
Ashfaq Reshad - avatar