The C++ Goes To Operator
What is the "-->" operator in 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. Here's the code: #include <stdio.h> int main() { int x = 10; while (x --> 0) // x goes to 0 { printf("%d ", x); } } I'd assume this is C, since it works in GCC as well. Where is this defined in the standard, and where has it come from?
A programming forum screenshot asks about the mysterious “-->” operator in C++. The joke is that it is actually parsed as a post-decrement followed by a greater-than comparison, making x gradually go to 0 rather than using a real operator. People share it as a reaction to clever-looking code, obscure language behavior, or confusing syntax.
- @ithueti / 28 2017-09-07
- Type
- image
- Size
- 756×405 · 36.7 KiB
- Mood
- clever, absurd
- Language
- en
- Added