+ 12
Why this program is printing 1?
12 ответов
+ 8
int x=10, y=20, z=5, i;
i=x<y<z
=
i=(x<y)<z;
👇
1. 10<20 = true, (true = 1);
2. 1<5 = true;
3. i = true, i = 1;
+ 10
Tanay Bhatt but bro if y<z is false then it should print 0.
Because 0 is false and 1 is true.
I think so...
+ 7
Given condition is true
In C program for boolean conditions
If true it will return the value as 1
Else false it will return 0
/*This will vary on different languages*/
So if you print the i in %d formatter it shows 1
+ 7
The precedence of the operators and associativity plays a role here
+ 6
Vasiliy Thank you very much😄
+ 5
x<y = true = 1: 10< 20
1<5=true=1
i=1
😎
+ 5
x< y = 10 < 20 ?
Yes , true = 1
1 < 5 ?
Yes , i = true = 1
+ 4
Bcz it a condition so check and ans is true so 1
+ 3
You are comparing nos.
int x =10,y=20,z=5,i
i=(x<y)<z //(10<20) it is true and returning 1, in the next part 1<5//result of (x<y)<z =1
so that's why you got 1
+ 2
It is a condition
and 1 is true
+ 1
Theres no bracket in x<y<z, and what Tanay Bhatt is saying is absolutely correct.. but the compiler reads value from left to right so x<y is computed first then the resultant with z so output is 1(also operation is same so no precedence issue)..
+ 1
sorry not tanay, Yamin Mansuri .. Am new to this app so mistake .. gomenasai