C Programming - Declarations and Initializations - Discussion
Discussion Forum : Declarations and Initializations - Find Output of Program (Q.No. 7)
7.
What is the output of the program
#include<stdio.h>
int main()
{
int x = 10, y = 20, z = 5, i;
i = x < y < z;
printf("%d\n", i);
return 0;
}
Answer: Option
Explanation:
Since x < y turns to be TRUE it is replaced by 1. Then 1 < z is compared and to be TRUE. The 1 is assigned to i.
Discussion:
37 comments Page 1 of 4.
Loelynk said:
2 years ago
Hello guys,
10<20(absolutely this condition is true.
True are 1
False are 0
The first x<1
Y are 1(true), that's time 1<5.
The second condition is also true(1), that 1 is passing through i.
10<20(absolutely this condition is true.
True are 1
False are 0
The first x<1
Y are 1(true), that's time 1<5.
The second condition is also true(1), that 1 is passing through i.
(2)
Rohan said:
8 years ago
What if it is from right to left?
(1)
Agnes said:
8 years ago
10<20=false ===>0
0<5=true===>1
Hence the output 1.
0<5=true===>1
Hence the output 1.
(1)
Bis said:
1 decade ago
What is the use of this code?
(1)
Indranil Roy said:
1 decade ago
I am explaining my thought.
#include<stdio.h>
int main()
{
int x = 10, y = 20, z = 5, i;
i = x < y < z;
printf("%d
", i);
return 0;
}
here i=10<20<5
Now c compiler starts execution from left side.
that is 10<20 returns TRUE and TRUE < 5 means 0 < 5 which is TRUE means Ans is 1
#include<stdio.h>
int main()
{
int x = 10, y = 20, z = 5, i;
i = x < y < z;
printf("%d
", i);
return 0;
}
here i=10<20<5
Now c compiler starts execution from left side.
that is 10<20 returns TRUE and TRUE < 5 means 0 < 5 which is TRUE means Ans is 1
Trisha said:
1 decade ago
What is the priority of =, < and > symbols. Can anyone explain?
Mary said:
1 decade ago
Can you explain what is the result if the case is like x>y>z?
Mostafa said:
1 decade ago
@Mary,
If x>y>z then,
10>20 return false "0".
0>5 return false "0".
The output will be 0.
If x>y>z then,
10>20 return false "0".
0>5 return false "0".
The output will be 0.
Shine said:
1 decade ago
can anyone tell me the priorities of < , > ,= operators?
Chitra said:
1 decade ago
I think <, > have equal priority and the = have lesser priority than <, >.
<, > assign the priority based on 1st come 1st order.
<, > assign the priority based on 1st come 1st order.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers