Confusion with ++ and -- operator
int a = 10;
printf("%d\n", -(--a) ); // valid
output: -9
But, problem occurs when following is used:
printf("%d\n", --(-a)); // error, invalid
Why?
The ++ and -- operator works on only lvalue, not value. An lvalue is something that can stand on the left side of an assignment.
printf("%d\n", -(--a) );
Here, -- operator works on variable a, so this is valid.
But,
printf("%d\n", --(-a));
Here, (-a) returns a value. -- is applied to a value, which is not valid.
This is because -- modifies a variable, and int value can't be modified (For example you can't do 7 = 5 but you can do a = 5)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With