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.
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.
Niharika said:
1 decade ago
I think #include<stdbool.h> Header file must be used to assign 1=true and 0=false but it is not used in the program.
How is it possible? to get output as 1 When we compare x<y.anyone explain?
How is it possible? to get output as 1 When we compare x<y.anyone explain?
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?
Sneha said:
1 decade ago
Explain me before program.
Richik said:
1 decade ago
What if one part is TRUE and another FALSE, what value of i will we take then?
Kumar Ajit said:
10 years ago
#include<stdio.h>
int main()
{
int x=10,y=20,z=5,i;
i=y>z>x;
printf("%d\n",i);
return 0;
}
Why out put is 0? I not understand friend explain it.
int main()
{
int x=10,y=20,z=5,i;
i=y>z>x;
printf("%d\n",i);
return 0;
}
Why out put is 0? I not understand friend explain it.
Rishi said:
9 years ago
Y>z = 20>5 true 1 then 1>10.
False 0.
1 true 1 false.
False 0.
1 true 1 false.
Ssindham said:
9 years ago
Your Explanation is perfect @Wikiok.
Kanniyappan said:
9 years ago
Is it possible to compare flag value < 5?
Naveen said:
1 decade ago
#include<stdio.h>
int main()
{
int x = 10, y = 20, z = 5, i;
i = x,y,z;
printf("%d\n", i);
return 0;
}
If you try the above code
step 1: = is having highest priority than ,
step2: i=10 will be initalized
step3: , operater will travell form left to right
So the out put will be 10.
int main()
{
int x = 10, y = 20, z = 5, i;
i = x,y,z;
printf("%d\n", i);
return 0;
}
If you try the above code
step 1: = is having highest priority than ,
step2: i=10 will be initalized
step3: , operater will travell form left to right
So the out put will be 10.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers