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.
3 Respuestas
+ 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.
+ 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;
}
0
c>b>a and '>' has associativity is left to right. So c>b evaluated first next (30>20) > a. => 1>10 false....