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.
Pradeep said:
3 years ago
Here, L VALUE Error because only one time initialise b takes value 100, only for second-time b before need L VALUE.
Nikhil g said:
8 years ago
Why to use parentheses? How compiler will get to know end of expressions based on parentheses? Explain it clearly.
Prafull said:
1 decade ago
How the err "Error: L value required for b" comes? Can anyone explain for me?
Thanx in advance.
Thanx in advance.
Maikal kumar said:
1 decade ago
Answer must be 100; because a=10 thats are >a. But please help me about lvalue value.
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;
Priyanka K. said:
1 decade ago
Condition is satisfying, hence b=100 will be assigned to b and it becomes print 100?
Pranali said:
8 years ago
@Gourav.
Because you are printing the value of b, so it will print 1.
Because you are printing the value of b, so it will print 1.
Durga said:
1 decade ago
Hi this program explanation is not clear. Please send brief expl.
Praveen said:
1 decade ago
Aloke would you please explain your program ? How does it work ?
Subbu said:
1 decade ago
What is the meaning of ? in between the a>=5 and b=100.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers