-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
  • 6,115
  • 16
  • 50
  • 57
supriya
  • 895
  • 1
  • 8
  • 18

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,378
  • 1
  • 14
  • 28