C: Why can't you increase / decrease a variable twice in one expression?

When I try to compile this code

int main() {
    int i = 0;
    ++(++i);
}

I am getting this error message.

test.c:3:5: error: lvalue required as increment operand
     ++(++i);
     ^

What is an error message? Is this something that the parser receives, or is it only detected during semantic analysis?

+4
source share
3 answers

++iwill give the value r 1 after evaluation, and you cannot apply ++to rvalue.

§6.5.3.1 (p1):

The operand of the increment or decrement prefix operator must be atomic, qualified, or unqualified, real or pointer type, and must be a mutable value of l .


< > 1. , "rvalue", " ". - §6.3.2.1 64).

+4

lvalue - , /assign.

++ i (i), ++ ++. , .

, ++ (, , ++ )

+2

, (++ i) , , , , c++ , ( , ), :

i += 2; 

or

i = i + 2;
+2
source

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


All Articles