什么是“ - >”的名称,运算符在C ++? [英] What is the name of the "-->" operator in C++?
问题描述
阅读 C ++ / STL的隐藏功能和暗角功能后, code> comp.lang.c ++。moderated ,我完全惊讶的是下面的代码片段在Visual Studio 2008和G ++ 4.4中编译和工作。
After reading Hidden Features and Dark Corners of C++/STL on comp.lang.c++.moderated
, I was completely surprised that the following snippet compiled and worked in both Visual Studio 2008 and G++ 4.4.
这里是代码:
#include <stdio.h>
int main()
{
int x = 10;
while (x --> 0) // x goes to 0
{
printf("%d ", x);
}
}
我假设这是C,在GCC以及。
I'd assume this is C, since it works in GCC as well. Where is this defined in the standard, and where has it come from?
推荐答案
- >
不是运算符。它实际上是两个单独的运算符, -
和>
。
-->
is not an operator. It is in fact two separate operators, --
and >
.
条件代码递减 x
,同时返回 x
的原始(非递减)值,然后使用>
运算符将原始值与 0
进行比较。
The conditional's code decrements x
, while returning x
's original (not decremented) value, and then compares the original value with 0
using the >
operator.
为了更好地理解,语句可以写成:
while( (x--) > 0 )
这篇关于什么是“ - >”的名称,运算符在C ++?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!