本文介绍了C和C ++中的几个一元运算符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否符合标准,使用
int i = 1;
+-+-+i;
以及如何确定i变量的符号?
and how the sign of i variable is determined?
推荐答案
是的。一元 +
和 -
从右到左关联,因此表达式解析为
Yes it is. Unary +
and -
associate right-to-left, so the expression is parsed as
+(-(+(-(+i))));
这会导致 1
。
请注意,这些可以重载,因此对于用户定义的类型,答案可能不同。
Note that these can be overloaded, so for a user-defined type the answer may differ.
这篇关于C和C ++中的几个一元运算符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!