+ 12

# Why this program is printing 1?

https://code.sololearn.com/c3nOT8fB9w7w/?ref=app

3rd May 2019, 7:36 AM
Yamin Mansuri + 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;
3rd May 2019, 7:48 AM
Solo + 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...
3rd May 2019, 7:41 AM
Yamin Mansuri + 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
3rd May 2019, 1:40 PM
Arvind Raj + 7
The precedence of the operators and associativity plays a role here
3rd May 2019, 1:44 PM
Arvind Raj + 6
Vasiliy Thank you very much😄
3rd May 2019, 9:17 AM
Yamin Mansuri + 5
x<y = true = 1: 10< 20 1<5=true=1 i=1 😎
3rd May 2019, 2:50 PM
Sanjay Kamath + 5
x< y = 10 < 20 ? Yes , true = 1 1 < 5 ? Yes , i = true = 1
4th May 2019, 8:56 AM
Yousef10 + 4
Bcz it a condition so check and ans is true so 1
3rd May 2019, 7:59 PM
Abhishek Bakhai + 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
4th May 2019, 3:01 AM
vijay + 2
It is a condition and 1 is true
3rd May 2019, 10:11 PM
Alonge Renfred + 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)..
3rd May 2019, 12:59 PM
Min_desu_ga + 1
sorry not tanay, Yamin Mansuri .. Am new to this app so mistake .. gomenasai
3rd May 2019, 1:00 PM
Min_desu_ga 