c++ 运算符python <<运算符 - C ++中的“ - >”运算符是什么？

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

`comp.lang.c++.moderated`上阅读C ++ / STL的Hidden Features和Dark Corners后 ，我完全惊讶于以下代码片段在Visual Studio 2008和G ++ 4.4中编译和工作。

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

``````while (x-- > 0)
``````

`x--` （后递减）相当于`x = x-1`所以，代码转换为：

``````while(x > 0) {
x = x-1;
// logic
}
``````

``````#include <stdio.h>
int main(void){
int x = 10;

while( x-- > 0 ){ // x goes to 0

printf("%d ", x);
}

return 0;
}
``````

``````while( x-- > 0 )
``````

``````x-->0
``````

``````token 1: x
token 2: --
token 3: >
token 4: 0
conclude: x-- > 0
``````

``````a-----b
``````

``````token 1: a
token 2: --
token 3: --
token 4: -
token 5: b
conclude: (a--)-- - b
``````

``````#include <iostream>
int main()
{
int x = 10;

while( x --> 0 ) // x goes to 0
{
std::cout << x;
}
}
``````

``````while( x > 0 )
{
x--;
std::cout << x;
}
``````

`--`递减运算符， `>`大于运算符。

``````-->    x-->0
++>    x++>0
-->=   x-->=0
++>=   x++>=0
``````

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

`x--`只是上述的简写， `>`只是一个普通的大于`operator` 。 没什么大不了的！