While compiling the code below I'm getting the error "lvalue required as left operand of assignment"
pra.c:5:20: error: lvalue required as left operand of assignment
The only thing wrong with the code as written is that you have
2n where you presumably should have
Your compiler seems to have decided that in
(i<=5)?j=1:j=i, the assignment operator on the right should bind less strongly than the conditional operator. This is incorrect and you should file a bug against the compiler. See operator precedence
An operand binds more tightly to an assignment operator on its right than to
:on its left
I assume adding a pair of parentheses around
j=i will make your code compile, although some consider it bad style to have assignment expressions as operands to the conditional operator, so a better thing to write is
j = (i <= 5 ? 1 : i).