Feeling confused with -(--a) vs --(-a) in c

风格不统一 提交于 2019-12-01 11:20:34

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)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!