C: Error while using: "Combined assignment" and "Prefix abbreviation" together

Can someone tell me why the compiler C

throws an error when using Compound Assignment

and at the same time Prefix Dec/Inc

? [but C++

doesn't work]

int myVar = 5;
(--myVar) -= 4;
// C  : error C2106: '-=' : left operand must be l-value
// C++: myVar=0;

      

I know what the error says ...

But I can't figure out why the compiler C

can't recognize myVar

as an l-value
, but C++

does ?!

+3


source to share


1 answer


In C, the prefix operator --

gives the value r. The r value cannot be the left operand of an assignment operator. However, C and C ++ are two different languages.



+6


source







All Articles