"error: lvalue required as left destination operand" in the conditional statement

I am new to C and today I learned "?" operator, which is a short if-else statement. However, when I execute this code:

int b;
int x;
b=3<2?x=12:x=34;

I get the error message "error: lvalue is required as the left destination operand". I do not understand why this is happening. The process, in my opinion, is that the program first assigns a value of 34 x, then assigns a value of x, which is equal to 34, b. On the other hand, I can use the statement as

int b;
int x;
b=3<2?x=12:(x=34);

no mistakes. I looked at my book, but nothing helped. Why can't I use the first statement? What is my computer trying to do? Thank...

+4
1

+1 - ++ C.

(1) C ++

++

logical-OR-expression ? expression : assignment-expression

, assignment-expression x=34

b = 3<2 ? x = 12 : (x = 34);

C

logical-OR-expression ? expression : conditional-expression 

x = 34 conditional-expression,

b = (3<2 ? x = 12 : x) = 34;

(2) ++ lvalue, C . , ++ , C:

b = (3<2 ? x = 12 : x) = 34;

ideone.com C ++. . c C ++ C ++ diff lvalue

+2

Source: https://habr.com/ru/post/1659648/


All Articles