0

What is output below the question?

#include<stdio.h> int main() { int a=10,b=20,c=30; if(c>b>a) { printf("true"); } else { printf("false"); } return 0; } What is answer above this code ? and how to answer is this can you explain me ? Not a syntax error.

23rd Oct 2020, 1:18 PM
Rutvikkumar Gondaliya
Rutvikkumar Gondaliya - avatar
3 Réponses
+ 1
It works like this: c>b ---> true, also called 1 1>a ---> false, also called 0 So the program execute the else rather than the if, printing false.
23rd Oct 2020, 1:25 PM
Davide
Davide - avatar
+ 4
Your code giving warnings because the operation which use using it have no mathematical meaning . It wont affected if use will use like this which u mentioned on program . So it will be better if u will use bracket with this type of operation of u can use check by using logical operators. See this i have used bracket it working without any warnings. #include<stdio.h> int main() { int a=10,b=20,c=30; if((c>b)>a) { printf("true"); } else { printf("false"); } return 0; }
23rd Oct 2020, 1:24 PM
A S Raghuvanshi
A S Raghuvanshi - avatar
0
c>b>a and '>' has associativity is left to right. So c>b evaluated first next (30>20) > a. => 1>10 false....
23rd Oct 2020, 1:40 PM
Jayakrishna 🇮🇳