-2

The code below

i>0?j=9:i=7;

Is giving an error:

lvalue required as left operand of assignment

Can you explain this why I am getting this error? when, i>0?j=9:(i=7); is working correctly

Kara
  • 5,996
  • 16
  • 49
  • 56
supriya
  • 795
  • 1
  • 7
  • 16

1 Answers1

0

Imho: basically your problem is that is C the termary operator has higher priority than "=" (in c++ the prioriy is equal, so it works as expected) and that is the reason you need the parenthesis.

kamil.rak
  • 1,358
  • 1
  • 14
  • 27