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 2 of 4.
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.
Manu sharma said:
1 decade ago
What if the program is like this:
main()
{
int a=4,b=2;
a=b<<a+b>>2;
printf("%d",a);
}
What will be the output?
main()
{
int a=4,b=2;
a=b<<a+b>>2;
printf("%d",a);
}
What will be the output?
Sai said:
1 decade ago
int main()
{
int x = 30, y = 20, z = 5, i;
i = x <y <z;
printf("%d\n", i);
return 0;
}
Please explain this program.
{
int x = 30, y = 20, z = 5, i;
i = x <y <z;
printf("%d\n", i);
return 0;
}
Please explain this program.
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.
Anmol said:
1 decade ago
No that's an wrong answer. If returning type would be Boolean that it would have been an correct answer.
Nikhil said:
1 decade ago
@Shiva
Ans is 0 because x>y is false so its return 0 & 0>5 also false so ans is 0.
Ans is 0 because x>y is false so its return 0 & 0>5 also false so ans is 0.
Deepu said:
1 decade ago
Ya < symbol have left associate. So, it complies from left to right.
The ans is "1".
The ans is "1".
Wikiok said:
1 decade ago
1. i=x<y<z
1. i=((10<20) < 5)
2. i=((1) < 5)
3. i=(1)
(True=1; False=0)
1. i=((10<20) < 5)
2. i=((1) < 5)
3. i=(1)
(True=1; False=0)
Richik said:
1 decade ago
What if one part is TRUE and another FALSE, what value of i will we take then?
Palak agrawal said:
1 decade ago
Yaa anyone tell the reason in above program. Why it is 10 not 20 or 30?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers