C Programming - Control Instructions - Discussion
Discussion Forum : Control Instructions - Point Out Errors (Q.No. 9)
9.
Point out the error, if any in the program.
#include<stdio.h>
int main()
{
int a = 10, b;
a >=5 ? b=100: b=200;
printf("%d\n", b);
return 0;
}
Answer: Option
Explanation:
Variable b is not assigned.
It should be like:
b = a >= 5 ? 100 : 200;
Discussion:
34 comments Page 3 of 4.
Maikal kumar said:
1 decade ago
Answer must be 100; because a=10 thats are >a. But please help me about lvalue value.
Praveen said:
1 decade ago
@Mani
The program which Aloke has posted works even though the expression a >=5 ? (b=100): (b=200); is not assigned to any value .. Would you please explain us in detail if you are clear with the concept ?
The program which Aloke has posted works even though the expression a >=5 ? (b=100): (b=200); is not assigned to any value .. Would you please explain us in detail if you are clear with the concept ?
Praveen said:
1 decade ago
Aloke would you please explain your program ? How does it work ?
Aloke said:
1 decade ago
#include<stdio.h>
int main()
{
int a = 10, b;
a >=5 ? (b=100): (b=200);
printf("%d\n", b);
return 0;
}
gives the output 100 on the online compilar which is provided by this site
check it my friends
int main()
{
int a = 10, b;
a >=5 ? (b=100): (b=200);
printf("%d\n", b);
return 0;
}
gives the output 100 on the online compilar which is provided by this site
check it my friends
Abhishek rai said:
1 decade ago
#include<stdio.h>
int main()
{
int a = 10, b;
a >=5 ? (b=100): (b=200);
printf("%d\n", b);
return 0;
}
int main()
{
int a = 10, b;
a >=5 ? (b=100): (b=200);
printf("%d\n", b);
return 0;
}
Rajat Rahul said:
1 decade ago
Mani is correct.
Mani said:
1 decade ago
Hi, You have to assign the value to any variable, but the exp a >=5 ? b=100: 200; is not assigned to any variable. So it gives the error msg of lvalue required.
Durga said:
1 decade ago
Hi this program explanation is not clear. Please send brief expl.
Vinoth said:
1 decade ago
L value means left side of the expression is equal to b.so
b=(a>=5)?b=100:b=200;
b=(a>=5)?b=100:b=200;
Vadya said:
1 decade ago
int a = 10, b;
a >=5 ? b=100: 200;
printf("%d\n", b);
This code works.! Why.???
How is it equivalent to b=(a>=5?100:200) ?
a >=5 ? b=100: 200;
printf("%d\n", b);
This code works.! Why.???
How is it equivalent to b=(a>=5?100:200) ?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers