Several unary operators in C and C++

前端 未结 3 1245
孤独总比滥情好
孤独总比滥情好 2021-01-26 05:18

Is it standard-conforming to use expressions like

int i = 1;
+-+-+i;

and how the sign of i variable is determined?

3条回答
  •  北荒
    北荒 (楼主)
    2021-01-26 05:51

    Your operators has no side effect, +i do nothing with int itself and you do not use the temporary generated value but remove + that do nothing and you have -(-i) witch is equal to i itself.(removing + in the code will convert the operator, I mean remove it in computation because it has no effect)

提交回复
热议问题