Several unary operators in C and C++

前端 未结 3 1248
孤独总比滥情好
孤独总比滥情好 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:53

    i isn't modified (C: without intervening sequence points|C++: in an unsequenced manner) so it's legal. You're just creating a new temporary with each operator.

    The unary + doesn't even do anything, so all you have is two negations which just give 1 for that expression. The variable i itself is never changed.

提交回复
热议问题