首页 > 其他 > 详细

What is the name of the “-->” operator?(Stackoverflow)

时间:2017-08-19 19:15:31      阅读:325      评论:0      收藏:0      [点我收藏+]

Question:

After reading Hidden Features and Dark Corners of C++/STL on comp.lang.c++.moderated, I was completely surprised that it compiled and worked in both Visual Studio 2008 and G++ 4.4.

The code:

#include <stdio.h>
int main()
{
     int x = 10;
     while( x --> 0 ) // x goes to 0
     {
       printf("%d ", x);
     }
}

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?

Answer:

That‘s not an operator -->. That‘s two separate operators, -- and >.

The condition code is decrementing x, while returning x‘s original (not decremented) value, and then comparing the original value with 0 using the > operator.

To better understand, the statement could be written as follows:

while( (x--) > 0 )

What is the name of the “--&gt;” operator?(Stackoverflow)

原文:http://www.cnblogs.com/slgkaifa/p/7397561.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!