Doubt: Are statements allowed in (?:)conditional operator ? Well, Yes Ofcourse! but without the semi-colon at the end!
Now, We might think that x>9 is TRUE and y=30 is TRUE Hence TRUE && TRUE becomes TRUE and TRUE is printed on screen, but we encounter
compile time error and the Error we get is :
error: lvalue required as left operand of assignment
lvalue: Any Variable that can be assigned a value and hence are permitted on the LHS of assignment operator.
rvalue: Any variable or constant whose value can be used in an expression or to assign value to lvalue.
It happens because the associativity of "and" operator "&&" is higher than Assignment Operator "=".
This converts the above statement in to
((x>9) && y) =30
i.e. TRUE && y = 30 // as y's current value is 20 , a non zero number,so
=> TRUE && TRUE =30
=> TRUE = 30 // TRUE=1 by default so the expression becomes,
And of course, A constant is not allowed on the Left hand side of the assignment operator as it is an rvalue!
To get correct output use parenthesis appropriately:
x=((x>9) && (y=30) ? printf("\nTRUE"): printf("\nFALSE"));