Q. What is the “-->” operator in C++?
Q. C++에서 "-->"연산자는 어떤 의미 안가요??
After reading Hidden Features and Dark Corners of C++/STL on comp.lang.c++.moderated, I was completely surprised that the following snippet compiled and worked in both Visual Studio 2008 and G++ 4.4.
comp.lang.c++.moderated에서 Hidden Features and Dark Corners of C++/STL 읽은 후에, 아래의 정보들이 Visual Studio 2008 랑 G++ 4.4 둘 모두에서 시용이 가능해서 놀랐습니다.
Here's the code:
#include <stdio.h>
int main()
{
int x = 10;
while (x --> 0) // x goes to 0
{
printf("%d ", x);
}
}
Output:
9 8 7 6 5 4 3 2 1 0
I'd assume this is C, since it works in GCC as well.
이 코드가 GCC에서도 잘 작동 되어서 C라고 생각했습니다.
Where is this defined in the standard, and where has it come from?
이 방법이 어디에서 유해 되었고, 표준으로 정의 되어 있다면 어디에 나와있나요?
--> is not an operator.
-->는 연산자가 아닙니다.
It is in fact two separate operators, -- and >.
이건 -- 와 > 두 개의 연산자입니다.
The conditional's code decrements x, while returning x's original (not decremented) value, and then compares the original value with 0 using the > operator.
x에 대한 --연산자는 x = x - 1의 연산을 수행합니다. 그리고, x값을 0과 >연산자를 이용해 비교합니다.
To better understand, the statement could be written as follows:
아래의 코드 처럼 실행되는 겁니다 :
while( (x--) > 0 )
decrement : N. 감소, 감소율 V. 감소를 나타내다