您的位置:首页 > 编程语言 > C语言/C++

c/c++中的-->运算符

2012-09-05 20:53 176 查看
参考What is the name of this operator: “–>”?

c/c++中以下代码是合法的:

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


-->是一个合法的操作符,我打赌自认c/c++熟手的你们都不知道这个操作符。有人称它为goes to操作符,x-->0表示x向0趋近。

其实我在忽悠你们。 并且我相信有很多人对此把戏相当熟悉。没错,-->只是两个操作符恰好遇在了一起,他们是自减运算符--和大于比较运算符>:

while (x-- > 0)
...


类似的把戏还有:

while (x -- \
\
\
\
> 0)
printf("%d ", x);


原文地址:http://codemacro.com/2012/09/03/goes-to-operator/

written byKevin Lynx posted athttp://codemacro.com
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: