# 數學運算 - c++语言

## C++中的“->”運算符是什麼? (14)

`-->`不是運營商。 它實際上是兩個獨立的運算符， `--``>`

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

`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);
}
}
``````

CC++遵守“最大蒙克”規則。 同樣的方式a --- b被翻譯成`(a--) - b` ，在你的情況下， `x-->0`轉換為`(x--)>0`

`--``>`之間缺少空格。 `x`後遞減，即在檢查條件`x>0 ?`後遞減`x>0 ?`

`--`遞減運算符， `>`大於運算符。

``````int abc(){
int a = 5
while((a--) > 0){ // Decrement and comparison both at once
// Code
}
}
``````

``````int abc(){
int a = 5
while(a > 0){
// Code
a = a -1 // Decrement inside loop
}
}
``````

``````#include<stdio.h>

int main()
{
int x = 10;

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

return 0;
}
``````

``````9 8 7 6 5 4 3 2 1 0
``````

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

`x--` （後遞減）相當於`x = x-1`所以，代碼轉換為：

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

``````#define as ;while

int main(int argc, char* argv[])
{
int n = atoi(argv[1]);
do printf("n is %d\n", n) as ( n --> 0);
return 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
``````

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

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

`x--`只是上述的簡寫， `>`只是一個普通的大於`operator` 。 沒什麼大不了的！

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

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

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