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 3 of 4.
Sugu said:
1 decade ago
How is it possible?
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".
Gangadhararao said:
1 decade ago
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;
}
Gow is the ouput becomes 1 ?
#include<stdio.h>
int main()
{
int x = 10, y = 20, z = 5, i;
i = x < y < z;
printf("%d\n", i);
return 0;
}
Gow is the ouput becomes 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)
Chelladurai said:
1 decade ago
Ya it is really good explanation.
Shiva said:
1 decade ago
Can anyone solve this one?
int main()
{
int x = 10, y = 20, z = 5, i;
i = x >y > z;
printf("%d\n", i);
return 0;
}
int main()
{
int x = 10, y = 20, z = 5, i;
i = x >y > z;
printf("%d\n", i);
return 0;
}
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.
Swetha said:
1 decade ago
Can you explain in depth? why it is replacing with 1?
Jayanth said:
2 decades ago
Is it correct explaination?
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;
}
step 1: In the above code < is having highest priority and = is having priority next to <
step 2: < symbol have left associate,so it will finish all the things with <
step 3: = is having next priority so values get into i
i=1.
int main()
{
int x = 10, y = 20, z = 5, i;
i = x < y < z;
printf("%d\n", i);
return 0;
}
step 1: In the above code < is having highest priority and = is having priority next to <
step 2: < symbol have left associate,so it will finish all the things with <
step 3: = is having next priority so values get into i
i=1.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers