main() { int a = 10, b = 7; a >= 5 ? b = 100 : b = 200; printf("B = %d\n",b); } When we compile this prg, I am getting an error like this: 3: error: lvalue required as left operand of assignment
@mathew: this will work fine, we know it.. the error is coming from ternary operator statment.. if you replace the statement like this "a>=5 ? b = 100 : 200", this will compile without any errors(lets not bother about o/p).. so just want to know what is wrong with the original statement.....
try this
ReplyDeletemain()
{
int a = 10, b = 7;
b= (a >= 5) ?100 : 200;
printf("B = %d\n",b);
}
@mathew: this will work fine, we know it.. the error is coming from ternary operator statment.. if you replace the statement like this "a>=5 ? b = 100 : 200", this will compile without any errors(lets not bother about o/p)..
ReplyDeleteso just want to know what is wrong with the original statement.....