Skip to content
Fix Code Error

What is the “–>” operator in C/C++?

March 13, 2021 by Code Error
Posted By: Anonymous

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

Output:

9 8 7 6 5 4 3 2 1 0

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?

Solution

--> 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.

To better understand, the statement could be written as follows:

while( (x--) > 0 )
Answered By: Anonymous

Related Articles

  • Fix top buttons on scroll of list below
  • Clang vs GCC - which produces faster binaries?
  • What is the worst programming language you ever worked with?
  • error LNK2005: ✘✘✘ already defined in…
  • don't know what went wrong nav bar with Tailwind CSS…
  • Getting infinite loop after entering 2 objects to…
  • problem with client server unix domain stream…
  • Is it possible to apply CSS to half of a character?
  • Does moment.js allow me to derive a timezone…
  • Why does C++ code for testing the Collatz conjecture…
  • How do I rotate text in css?
  • How to properly do JSON API GET requests and assign…
  • How to add 'load more' functionality to items on a…
  • Obtain most recent value for based on index in a…
  • List of Timezone IDs for use with FindTimeZoneById() in C#?
  • How to Detect if I'm Compiling Code with a…
  • How to render a list of static content with Vue named slot?
  • How to implement routing in polymer 3 using app-route
  • Why can't I get the value of asm registers in C?
  • CMake error at CMakeLists.txt:30 (project): No…
  • I wrote a simple python game but functions in that…
  • Unity Scripts edited in Visual studio don't provide…
  • OpenCL - Approximation of Pi via Monte Carlo…
  • Null check in VB
  • How to change the default GCC compiler in Ubuntu?
  • Detect if Visual C++ Redistributable for Visual…
  • Load json from local file with http.get() in angular 2
  • Best practices for circular shift (rotate) operations in C++
  • What does this symbol mean in JavaScript?
  • SDL_SetRenderTarget() hangs for a while if multiple…
  • How to notify array mutation to parent component in…
  • Centering in CSS Grid
  • no match for ‘operator
  • Cannot open include file: 'stdio.h' - Visual Studio…
  • Adding a guideline to the editor in Visual Studio
  • Is gcc's __attribute__((packed)) / #pragma pack unsafe?
  • SMTP error 554
  • Callback functions in C++
  • How can I create an executable to run a kernel in a…
  • Can't find file executable in your configured search…
  • Efficient Algorithm for Bit Reversal (from…
  • What are the undocumented features and limitations…
  • #define macro for debug printing in C?
  • Aurelia/Karma/Istanbul Cannot read property 'skip'…
  • Siemens LOGO! PLC data in the wrong order
  • How to parse JSON with XE2 dbxJSON
  • What is the scope of variables in JavaScript?
  • How to install the Raspberry Pi cross compiler on my…
  • For-each over an array in JavaScript
  • Reference — What does this symbol mean in PHP?
  • fork() and wait() with two child processes
  • Implementation of user defined array on stack and/or…
  • Why does the C preprocessor interpret the word…
  • CSS3's border-radius property and…
  • configure: error: C compiler cannot create executables
  • How to completely uninstall Visual Studio 2010?
  • How to implement an STL-style iterator and avoid…
  • How do SO_REUSEADDR and SO_REUSEPORT differ?
  • Azure Availability Zone ARM Config
  • Why is my loop stopping at the first argument (char…
  • how to install gcc on windows 7 machine?
  • delete item in array of struct that has char array…
  • Event Snippet for Google only shows one event while…
  • The 'compilation' argument must be an instance of…
  • gcc/g++: "No such file or directory"
  • MySQL Data Source not appearing in Visual Studio
  • Vector of array fails to compile
  • Why can I not push_back a unique_ptr into a vector?
  • Can't add C# class in visual studio 2019 anymore -…
  • loop and eliminate unwanted lines with beautiful soup
  • Trouble understanding behaviour of modified VGG16…
  • Changing CSS variable based on the parent class ||…
  • mongodb group values by multiple fields
  • Searching for matching elements between 2 arrays in C
  • What is a NullReferenceException, and how do I fix it?
  • Smart way to truncate long strings
  • Is there any possible way to loop strcmp function in…
  • Compile a DLL in C/C++, then call it from another program
  • NullpointerException error while working with…
  • What is the difference between Visual Studio Express…
  • Why does the function named "traverse" not work on my code?
  • Why is 2 * (i * i) faster than 2 * i * i in Java?
  • Why does declared array size not affect the size of…
  • Best way to do multi-row insert in Oracle?
  • How can I find the product GUID of an installed MSI setup?
  • What does java:comp/env/ do?
  • Could not load file or assembly…
  • mmap memory backed by other memory?
  • Persistent invalid graphics state error when using ggplot2
  • How remove class step by step
  • I was expecting segmentation fault or some kind of…
  • data.table vs dplyr: can one do something well the…
  • How to allocate aligned memory only using the…
  • How can I manually compile a svelte component down…
  • Visual Studio 2015 or 2017 does not discover unit tests
  • Search match multiple values in single field in…
  • How do I limit the number of digits from 6 to 4 in…
  • Visual Studio debugging/loading very slow
  • How to write an application to control a driver…
  • Creating an dynamic array, but getting segmentation…

Disclaimer: This content is shared under creative common license cc-by-sa 3.0. It is generated from StackExchange Website Network.

Post navigation

Previous Post:

How to keep one variable constant with other one changing with row in excel

Next Post:

ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

.net ajax android angular arrays aurelia backbone.js bash c++ css dataframe ember-data ember.js excel git html ios java javascript jquery json laravel linux list mysql next.js node.js pandas php polymer polymer-1.0 python python-3.x r reactjs regex sql sql-server string svelte typescript vue-component vue.js vuejs2 vuetify.js

  • you shouldn’t need to use z-index
  • No column in target database, but getting “The schema update is terminating because data loss might occur”
  • Angular – expected call-signature: ‘changePassword’ to have a typedeftslint(typedef)
  • trying to implement NativeAdFactory imports deprecated method by default in flutter java project
  • What should I use to get an attribute out of my foreign table in Laravel?
© 2022 Fix Code Error