types of operators in c++ - What is the “-->” operator in C++?

logical operators in c++ with example program / c++ / c / operators / code-formatting / standards-compliance

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.

Here's the code:

#include <stdio.h>
int main()
{
    int x = 10;
    while (x --> 0) // x goes to 0
    {
        printf("%d ", x);
    }
}
9 8 7 6 5 4 3 2 1 0

37 revs, 25 users 24%



Answer #1
#include <stdio.h>

int main(void) {
  int x = 10;
  while (x-- > 0) { // x goes to 0
    printf("%d ", x);
  }
  return 0;
}