Error: lvalue required in this simple C code? (Ternary with assignment?)

Viewed 10433

I have :

#include<stdio.h>

int main()
{
 int a=5,b=6;
 (a>b)?b=a:b=b;    // Here is the error
 return 0;
}

But if I replace :

(a>b)?b=a:b=b;       // Error
with   
(a>b)?(b=a):(b=b);   // No-Error

I understand the lvalue is a value to which something can be assigned and how is it different from rvalue, but why is the extra parenthesis making the difference.

4 Answers
Related