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;
}
100
200
Error: L value required for b
Garbage value
Answer: Option
Explanation:

Variable b is not assigned.

It should be like:

b = a >= 5 ? 100 : 200;

Discussion:
34 comments Page 4 of 4.

Ankit said:   1 decade ago
Still I don't understood.

Vishal yadav said:   1 decade ago
It comes because on the left side of the assignment operator there are more than two variables having ? between the if you use (b=100) instead of it, there will be no error.

Prafull said:   1 decade ago
How the err "Error: L value required for b" comes? Can anyone explain for me?

Thanx in advance.

Sandy said:   1 decade ago
It gives output as 100 when executed on DEV C++.


Post your comments here:

Your comments will be displayed after verification.