C++ 中的 --> 操作符

--> 并不是一个操作符,实际上它是两个独立的操作符:-- 和 >。

以下代码中我们设置了一个 x 自减的条件运算符代码,在 x 的进行自减运算前,会先使用比较符号 > 与右边表达式 0 进行比较,然后返回结果再进行自减运算:

while (x --> 0)

// 相等于以下代码
while( (x--) > 0 )
// 把两个运算符分开更好理解了

while (x-- > 0)

实例 1:输出 0 到 9 的 整数

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

输出结果:

9 8 7 6 5 4 3 2 1 0

实例 2: 输出 大于 0 小于 10 的偶数

#include <stdio.h>
int main()
{

    int x = 10;

    while( 0 <---- x )
    {
       printf("%d ", x);
    }
}

输出结果:

8 6 4 2

实例 3

#include <stdio.h>
int main()
{
    int x = 100;

    while( 0 <-------------------- x )
    {
       printf("%d ", x);
    }
}

输出结果:

90 80 70 60 50 40 30 20 10
原文地址:https://www.cnblogs.com/gkh-whu/p/11478288.html