🕷️ Crawler Inspector

URL Lookup

Direct Parameter Lookup

Raw Queries and Responses

1. Shard Calculation

Query:
Response:
Calculated Shard: 169 (from laksa036)

2. Crawled Status Check

Query:
Response:

3. Robots.txt Check

Query:
Response:

4. Spam/Ban Check

Query:
Response:

5. Seen Status Check

ℹ️ Skipped - page is already crawled

📄
INDEXABLE
CRAWLED
15 days ago
🤖
ROBOTS ALLOWED

Page Info Filters

FilterStatusConditionDetails
HTTP statusPASSdownload_http_code = 200HTTP 200
Age cutoffPASSdownload_stamp > now() - 6 MONTH0.5 months ago
History dropPASSisNull(history_drop_reason)No drop reason
Spam/banPASSfh_dont_index != 1 AND ml_spam_score = 0ml_spam_score=0
CanonicalPASSmeta_canonical IS NULL OR = '' OR = src_unparsedNot set

Page Details

PropertyValue
URLhttps://stackoverflow.com/questions/1642028/what-is-the-operator-in-c-c
Last Crawled2026-04-11 19:04:04 (15 days ago)
First Indexed2021-02-11 17:09:53 (5 years ago)
HTTP Status Code200
Content
Meta TitleWhat is the '-->' operator in C/C++? - Stack Overflow
Meta Descriptionnull
Meta Canonicalnull
Boilerpipe Text
--> is not an operator, it is the juxtaposition of -- (post-decrement) and > (greater than comparison). The loop will look more familiar as: # include <stdio.h> int main () { int x = 10 ; while (x-- > 0 ) { // x goes to 0 printf ( "%d " , x); } } This loop is a classic idiom to enumerate values between 10 (the excluded upper bound) and 0 the included lower bound, useful to iterate over the elements of an array from the last to the first. The initial value 10 is the total number of iterations (for example the length of the array), and one plus the first value used inside the loop. The 0 is the last value of x inside the loop, hence the comment x goes to 0 . Note that the value of x after the loop completes is -1 . Note also that this loop will operate the same way if x has an unsigned type such as size_t , which is a strong advantage over the naive alternative for (i = length-1; i >= 0; i--) . For this reason, I am actually a fan of this surprising syntax: while (x --> 0) . I find this idiom eye-catching and elegant, just like for (;;) vs: while (1) (which looks confusingly similar to while (l) ). It also works in other languages whose syntax is inspired by C: C++, Objective-C, java, javascript, C# to name a few.
Markdown
# ![site logo](https://stackoverflow.com/Content/Img/SE-logo75.png) By clicking “Sign up”, you agree to our [terms of service](https://stackoverflow.com/legal/terms-of-service/public) and acknowledge you have read our [privacy policy](https://stackoverflow.com/legal/privacy-policy). # OR Already have an account? [Log in](https://stackoverflow.com/users/login) [Skip to main content](https://stackoverflow.com/questions/1642028/what-is-the-operator-in-c-c#content) 1. [About](https://stackoverflow.co/) 2. Products 3. [For Teams](https://stackoverflow.co/internal/) 4. Try new site Try BETA 1. [Stack Internal Implement a knowledge platform layer to power your enterprise and AI tools.](https://stackoverflow.co/internal/?utm_medium=referral&utm_source=stackoverflow-community&utm_campaign=top-nav&utm_content=stack-overflow-for-teams) 2. [Stack Data Licensing Get access to top-class technical expertise with trusted & attributed content.](https://stackoverflow.co/data-licensing/?utm_medium=referral&utm_source=stackoverflow-community&utm_campaign=top-nav&utm_content=overflow-api) 3. [Stack Ads Connect your brand to the world’s most trusted technologist communities.](https://stackoverflow.co/advertising/?utm_medium=referral&utm_source=stackoverflow-community&utm_campaign=top-nav&utm_content=stack-overflow-advertising) 4. [Releases Keep up-to-date on features we add to Stack Overflow and Stack Internal.](https://stackoverflow.blog/releases/?utm_medium=referral&utm_source=stackoverflow-community&utm_campaign=top-nav&utm_content=releases) 5. [About the company](https://stackoverflow.co/?utm_medium=referral&utm_source=stackoverflow-community&utm_campaign=top-nav&utm_content=about-the-company) [Visit the blog](https://stackoverflow.blog/?utm_medium=referral&utm_source=stackoverflow-community&utm_campaign=top-nav&utm_content=blog) 1. ### [current community](https://stackoverflow.com/) - [Stack Overflow](https://stackoverflow.com/) [help](https://stackoverflow.com/help) [chat](https://chat.stackoverflow.com/?tab=explore) - [Meta Stack Overflow](https://meta.stackoverflow.com/) ### your communities [Sign up](https://stackoverflow.com/users/signup?ssrc=site_switcher&returnurl=https%3A%2F%2Fstackoverflow.com%2Fquestions%2F1642028%2Fwhat-is-the-operator-in-c-c) or [log in](https://stackoverflow.com/users/login?ssrc=site_switcher&returnurl=https%3A%2F%2Fstackoverflow.com%2Fquestions%2F1642028%2Fwhat-is-the-operator-in-c-c) to customize your list. ### [more stack exchange communities](https://stackexchange.com/sites) [company blog](https://stackoverflow.blog/) 2. [Log in](https://stackoverflow.com/users/login?ssrc=head&returnurl=https%3A%2F%2Fstackoverflow.com%2Fquestions%2F1642028%2Fwhat-is-the-operator-in-c-c) 3. [Sign up](https://stackoverflow.com/users/signup?ssrc=head&returnurl=https%3A%2F%2Fstackoverflow.com%2Fquestions%2F1642028%2Fwhat-is-the-operator-in-c-c) # Let's set up your homepage Select a few topics you're interested in: python javascript c\# reactjs java android html flutter c++ node.js typescript css r php angular next.js spring-boot machine-learning sql excel ios azure docker Or search from our full list: - javascript - python - java - c\# - php - android - html - jquery - c++ - css - ios - sql - mysql - r - reactjs - node.js - arrays - c - asp.net - json - python-3.x - .net - ruby-on-rails - sql-server - swift - django - angular - objective-c - excel - pandas - angularjs - regex - typescript - ruby - linux - ajax - iphone - vba - xml - laravel - spring - asp.net-mvc - database - wordpress - string - flutter - postgresql - mongodb - wpf - windows - xcode - amazon-web-services - bash - git - oracle-database - spring-boot - dataframe - azure - firebase - list - multithreading - docker - vb.net - react-native - eclipse - algorithm - powershell - macos - visual-studio - numpy - image - forms - scala - function - vue.js - performance - twitter-bootstrap - selenium - winforms - kotlin - loops - dart - express - sqlite - hibernate - matlab - python-2.7 - shell - rest - apache - entity-framework - android-studio - csv - maven - linq - qt - dictionary - unit-testing - asp.net-core - facebook - apache-spark - tensorflow - file - swing - class - unity-game-engine - sorting - date - authentication - go - symfony - t-sql - opencv - matplotlib - .htaccess - google-chrome - for-loop - datetime - codeigniter - perl - http - validation - sockets - google-maps - object - uitableview - xaml - oop - visual-studio-code - if-statement - cordova - ubuntu - web-services - email - android-layout - github - spring-mvc - elasticsearch - kubernetes - selenium-webdriver - ms-access - ggplot2 - user-interface - parsing - pointers - google-sheets - c++11 - security - machine-learning - google-apps-script - ruby-on-rails-3 - templates - flask - nginx - variables - exception - sql-server-2008 - gradle - debugging - tkinter - delphi - listview - jpa - asynchronous - haskell - web-scraping - jsp - pdf - ssl - amazon-s3 - google-cloud-platform - xamarin - testing - jenkins - wcf - batch-file - generics - npm - ionic-framework - network-programming - unix - recursion - google-app-engine - mongoose - visual-studio-2010 - .net-core - android-fragments - assembly - animation - math - rust - svg - session - intellij-idea - hadoop - join - winapi - curl - django-models - laravel-5 - next.js - url - heroku - http-redirect - tomcat - inheritance - google-cloud-firestore - webpack - gcc - swiftui - image-processing - keras - asp.net-mvc-4 - logging - dom - matrix - pyspark - actionscript-3 - button - post - optimization - firebase-realtime-database - cocoa - jquery-ui - xpath - iis - d3.js - web - javafx - firefox - xslt - internet-explorer - caching - select - asp.net-mvc-3 - opengl - events - asp.net-web-api - plot - dplyr - encryption - magento - stored-procedures - search - amazon-ec2 - ruby-on-rails-4 - memory - multidimensional-array - canvas - audio - random - jsf - vector - redux - cookies - input - facebook-graph-api - flash - indexing - xamarin.forms - arraylist - ipad - cocoa-touch - data-structures - video - model-view-controller - azure-devops - serialization - apache-kafka - jdbc - razor - awk - woocommerce - routes - mod-rewrite - servlets - excel-formula - beautifulsoup - filter - iframe - docker-compose - design-patterns - aws-lambda - text - visual-c++ - django-rest-framework - cakephp - mobile - android-intent - struct - react-hooks - methods - groovy - mvvm - lambda - ssh - time - checkbox - ecmascript-6 - grails - installation - google-chrome-extension - cmake - sharepoint - shiny - spring-security - jakarta-ee - plsql - android-recyclerview - core-data - types - sed - meteor - android-activity - bootstrap-4 - activerecord - replace - websocket - graph - group-by - scikit-learn - vim - file-upload - boost - junit - memory-management - sass - async-await - import - deep-learning - error-handling - eloquent - dynamic - dependency-injection - silverlight - soap - layout - apache-spark-sql - charts - deployment - browser - gridview - svn - while-loop - google-bigquery - vuejs2 - highcharts - dll - ffmpeg - view - foreach - makefile - plugins - redis - c\#-4.0 - reporting-services - jupyter-notebook - unicode - merge - reflection - https - server - google-maps-api-3 - twitter - oauth-2.0 - extjs - terminal - pip - axios - split - cmd - encoding - pytorch - django-views - collections - database-design - hash - automation - netbeans - data-binding - ember.js - build - tcp - pdo - apache-flex - sqlalchemy - entity-framework-core - concurrency - command-line - spring-data-jpa - printing - react-redux - java-8 - lua - html-table - neo4j - ansible - service - jestjs - enums - parameters - flexbox - material-ui - module - promise - visual-studio-2012 - mysqli - outlook - web-applications - uwp - webview - firebase-authentication - jquery-mobile - utf-8 - datatable - python-requests - parallel-processing - colors - drop-down-menu - scipy - tfs - scroll - hive - count - syntax - ms-word - twitter-bootstrap-3 - ssis - fonts - rxjs - constructor - file-io - google-analytics - paypal - three.js - powerbi - cassandra - graphql - discord - graphics - compiler-errors - gwt - react-router - socket.io - backbone.js - memory-leaks - solr - url-rewriting - datatables - nlp - terraform - oauth - datagridview - drupal - zend-framework - oracle11g - knockout.js - triggers - interface - neural-network - django-forms - casting - angular-material - jmeter - linked-list - google-api - path - timer - arduino - django-templates - orm - windows-phone-7 - directory - proxy - parse-platform - visual-studio-2015 - cron - conditional-statements - push-notification - functional-programming - primefaces - pagination - model - jar - xamarin.android - hyperlink - uiview - visual-studio-2013 - vbscript - google-cloud-functions - azure-active-directory - gitlab - jwt - download - swift3 - sql-server-2005 - pygame - rspec - process - configuration - properties - callback - combobox - windows-phone-8 - linux-kernel - safari - scrapy - emacs - permissions - x86 - clojure - scripting - raspberry-pi - io - scope - azure-functions - compilation - responsive-design - mongodb-query - nhibernate - expo - angularjs-directive - reference - architecture - binding - bluetooth - request - dns - playframework - 3d - version-control - pyqt - discord.js - doctrine-orm - package - f\# - rubygems - get - sql-server-2012 - autocomplete - tree - datepicker - openssl - kendo-ui - jackson - yii - controller - grep - nested - xamarin.ios - static - null - transactions - statistics - datagrid - active-directory - uiviewcontroller - dockerfile - webforms - sas - computer-vision - discord.py - phpmyadmin - notifications - duplicates - pycharm - mocking - youtube - nullpointerexception - yaml - menu - blazor - sum - plotly - bitmap - visual-studio-2008 - asp.net-mvc-5 - floating-point - yii2 - css-selectors - stl - android-listview - electron - jsf-2 - time-series - cryptography - ant - hashmap - character-encoding - msbuild - stream - asp.net-core-mvc - sdk - google-drive-api - selenium-chromedriver - jboss - joomla - devise - cuda - navigation - cors - frontend - anaconda - background - multiprocessing - binary - pyqt5 - camera - iterator - linq-to-sql - mariadb - onclick - ios7 - android-jetpack-compose - microsoft-graph-api - android-asynctask - rabbitmq - tabs - amazon-dynamodb - environment-variables - laravel-4 - uicollectionview - insert - linker - coldfusion - xsd - console - continuous-integration - upload - textview - ftp - opengl-es - macros - operating-system - mockito - localization - formatting - xml-parsing - json.net - type-conversion - vuejs3 - data.table - kivy - timestamp - integer - calendar - segmentation-fault - android-ndk - prolog - char - drag-and-drop - crash - jasmine - azure-pipelines - dependencies - automated-tests - geometry - fortran - android-gradle-plugin - itext - sprite-kit - mfc - header - attributes - nosql - format - firebase-cloud-messaging - nuxt.js - odoo - db2 - jquery-plugins - event-handling - julia - jenkins-pipeline - leaflet - annotations - flutter-layout - keyboard - nestjs - postman - arm - textbox - stripe-payments - visual-studio-2017 - gulp - libgdx - uikit - timezone - synchronization - azure-web-app-service - dom-events - wso2 - google-sheets-formula - xampp - crystal-reports - aggregation-framework - namespaces - android-emulator - uiscrollview - swagger - jvm - sequelize.js - chart.js - com - snowflake-cloud-data-platform - subprocess - html5-canvas - geolocation - garbage-collection - webdriver - sql-update - dialog - centos - concatenation - numbers - widget - qml - tuples - set - java-stream - mapreduce - ionic2 - smtp - windows-10 - android-edittext - rotation - nuget - modal-dialog - spring-data - radio-button - doctrine - http-headers - grid - lucene - sonarqube - xmlhttprequest - listbox - initialization - switch-statement - internationalization - boolean - components - apache-camel - google-play - gdb - serial-port - ios5 - return - ldap - youtube-api - pivot - eclipse-plugin - latex - frameworks - tags - containers - c++17 - subquery - github-actions - embedded - dataset - foreign-keys - asp-classic - label - uinavigationcontroller - delegates - copy - google-cloud-storage - struts2 - migration - protractor - base64 - uibutton - queue - sql-server-2008-r2 - find - arguments - composer-php - append - jaxb - stack - zip - tailwind-css - cucumber - autolayout - ide - entity-framework-6 - iteration - popup - r-markdown - windows-7 - vb6 - clang - g++ - airflow - hover - ssl-certificate - jqgrid - range - gmail Next You’ll be prompted to create an account to view your personalized homepage. 1. 1. [Home](https://stackoverflow.com/) 2. [Questions](https://stackoverflow.com/questions) 3. [AI Assist](https://stackoverflow.com/ai-assist) 4. [Tags](https://stackoverflow.com/tags) 5. [Challenges](https://stackoverflow.com/beta/challenges) 6. [Chat](https://chat.stackoverflow.com/?tab=explore) 7. [Articles](https://stackoverflow.blog/contributed?utm_medium=referral&utm_source=stackoverflow-community&utm_campaign=so-blog&utm_content=experiment-articles) 8. [Users](https://stackoverflow.com/users) 9. [Companies](https://stackoverflow.com/jobs/companies?so_medium=stackoverflow&so_source=SiteNav) 10. [Collectives]() 11. Communities for your favorite technologies. [Explore all Collectives](https://stackoverflow.com/collectives-all) 2. Stack Internal Stack Overflow for Teams is now called **Stack Internal**. Bring the best of human thought and AI automation together at your work. [Try for free](https://stackoverflowteams.com/teams/create/free/?utm_medium=referral&utm_source=stackoverflow-community&utm_campaign=side-bar&utm_content=explore-teams) [Learn more](https://stackoverflow.co/internal/?utm_medium=referral&utm_source=stackoverflow-community&utm_campaign=side-bar&utm_content=explore-teams) 3. [Stack Internal]() 4. Bring the best of human thought and AI automation together at your work. [Learn more](https://stackoverflow.co/internal/?utm_medium=referral&utm_source=stackoverflow-community&utm_campaign=side-bar&utm_content=explore-teams-compact) ##### Collectives™ on Stack Overflow Find centralized, trusted content and collaborate around the technologies you use most. [Learn more about Collectives](https://stackoverflow.com/collectives) **Stack Internal** Knowledge at work Bring the best of human thought and AI automation together at your work. [Explore Stack Internal](https://stackoverflow.co/internal/?utm_medium=referral&utm_source=stackoverflow-community&utm_campaign=side-bar&utm_content=explore-teams-compact-popover) # [What is the '--\>' operator in C/C++?](https://stackoverflow.com/questions/1642028/what-is-the-operator-in-c-c) [Ask Question](https://stackoverflow.com/questions/ask) Asked 16 years, 5 months ago Modified [3 months ago](https://stackoverflow.com/questions/1642028/what-is-the-operator-in-c-c?lastactivity "2025-11-28 13:14:41Z") Viewed 1.1m times This question shows research effort; it is useful and clear 10262 Save this question. Show activity on this post. After reading [Hidden Features and Dark Corners of C++/STL](http://groups.google.com/group/comp.lang.c++.moderated/msg/33f173780d58dd20) 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. I would assume this is also valid C since it works in GCC as well. Here's the code: ``` Copy ``` Output: ``` 9 8 7 6 5 4 3 2 1 0 ``` Where is this defined in the standard, and where has it come from? - [c++](https://stackoverflow.com/questions/tagged/c%2B%2B "show questions tagged 'c++'") - [c](https://stackoverflow.com/questions/tagged/c "show questions tagged 'c'") - [operators](https://stackoverflow.com/questions/tagged/operators "show questions tagged 'operators'") - [code-formatting](https://stackoverflow.com/questions/tagged/code-formatting "show questions tagged 'code-formatting'") - [standards-compliance](https://stackoverflow.com/questions/tagged/standards-compliance "show questions tagged 'standards-compliance'") [Share](https://stackoverflow.com/q/1642028 "Short permalink to this question") Share a link to this question Copy link [CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/ "The current license for this post: CC BY-SA 4.0") [Improve this question](https://stackoverflow.com/posts/1642028/edit) Follow Follow this question to receive notifications [edited Mar 30, 2023 at 14:11](https://stackoverflow.com/posts/1642028/revisions "show all edits to this post") community wiki [43 revs, 29 users 22%](https://stackoverflow.com/posts/1642028/revisions "show revision history for this post") [GManNickG](https://stackoverflow.com/users/87234) 3 - 6 The most dangerous feature of this construct is that it starts with 9 instead of 10. The same is true for `for (int x = 10; x-->0;)`. Sebastian – [Sebastian](https://stackoverflow.com/users/13130048/sebastian "2,016 reputation") 2024-04-18 07:45:14 +00:00 [Commented Apr 18, 2024 at 7:45](https://stackoverflow.com/questions/1642028/what-is-the-operator-in-c-c#comment138121234_1642028) - 7 @Sebastian: yes, `for (int x = 10; x --> 0;)` starts at `9` and iterates down to `0` included. This is a **feature**, not necessarily intuitive for everyone, but very handy to enumerate entries in an array where the initial value of `x` is the length of the array: `for (size_t i = sizeof(a) / sizeof(a[0]); i --> 0;) { /* do something with a[i] */ }` chqrlie – [chqrlie](https://stackoverflow.com/users/4593267/chqrlie "153,029 reputation") 2024-04-18 08:08:02 +00:00 [Commented Apr 18, 2024 at 8:08](https://stackoverflow.com/questions/1642028/what-is-the-operator-in-c-c#comment138121474_1642028) - 6 I think, it's vald in many languages which have postfix --. THis is 40 year-old running joke. Every 2-3 years there is a question about it XD Swift - Friday Pie – [Swift - Friday Pie](https://stackoverflow.com/users/2742717/swift-friday-pie "15,603 reputation") 2024-04-26 07:35:11 +00:00 [Commented Apr 26, 2024 at 7:35](https://stackoverflow.com/questions/1642028/what-is-the-operator-in-c-c#comment138197147_1642028) [Add a comment](https://stackoverflow.com/questions/1642028/what-is-the-operator-in-c-c "Use comments to ask for more information or suggest improvements. Avoid answering questions in comments.") \| ## 26 Answers 26 Sorted by: [Reset to default](https://stackoverflow.com/questions/1642028/what-is-the-operator-in-c-c?answertab=scoredesc#tab-top) This answer is useful 9963 Save this answer. \+50 This answer has been awarded bounties worth 50 reputation by Community Show activity on this post. `-->` is not an operator. It is in fact two separate operators, `--` and `>`. The code in the condition 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:** ``` Copywhile( (x--) > 0 ) ``` [Share](https://stackoverflow.com/a/1642035 "Short permalink to this answer") Share a link to this answer Copy link [CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/ "The current license for this post: CC BY-SA 4.0") [Improve this answer](https://stackoverflow.com/posts/1642035/edit) Follow Follow this answer to receive notifications [edited Aug 25, 2023 at 21:34](https://stackoverflow.com/posts/1642035/revisions "show all edits to this post") community wiki [14 revs, 13 users 16%](https://stackoverflow.com/posts/1642035/revisions "show revision history for this post") [Bradley Mackey](https://stackoverflow.com/users/3261161) Sign up to request clarification or add additional context in comments. ## 5 Comments Add a comment [![](https://www.gravatar.com/avatar/69f5ea15c6262d41bde8b1864e8d698e?s=48&d=identicon&r=PG)](https://stackoverflow.com/users/2513804/moshe-bildner) Moshe Bildner [Moshe Bildner](https://stackoverflow.com/users/2513804/moshe-bildner) [Over a year ago](https://stackoverflow.com/questions/1642028/what-is-the-operator-in-c-c#comment119493280_1642035) I've seen it jokingly referred to as the "downto" operator ([codegolf.stackexchange.com/questions/16226/…](https://codegolf.stackexchange.com/questions/16226/i-need-a-program-where-the-user-inputs-an-array-of-doubles-and-the-program-outpu/16232#16232 "i need a program where the user inputs an array of doubles and the program outpu")) 2021-05-19T13:26:37.877Z+00:00 103 Reply - Copy link [![](https://i.sstatic.net/vXG1F.png?s=64)](https://stackoverflow.com/users/14860/paxdiablo) paxdiablo [paxdiablo](https://stackoverflow.com/users/14860/paxdiablo) [Over a year ago](https://stackoverflow.com/questions/1642028/what-is-the-operator-in-c-c#comment120592100_1642035) I think you wouldn't really *need* the parentheses around `x--` though it does further enforce the separation. It would probably be enough just to associate tokens more clearly with something like `while (x-- > 0)`. 2021-07-03T01:18:31.747Z+00:00 19 Reply - Copy link [![](https://www.gravatar.com/avatar/c2c82b4efc698d359dbeb8766e132c99?s=48&d=identicon&r=PG&f=y&so-version=2)](https://stackoverflow.com/users/9236273/vineet) Vineet [Vineet](https://stackoverflow.com/users/9236273/vineet) [Over a year ago](https://stackoverflow.com/questions/1642028/what-is-the-operator-in-c-c#comment131287698_1642035) The most important reason to use this operator is I believe to avoid the "off-by-one" errors that occur when traversing an array in reverse It's quite easier to use for(int i = n; i--\>0;) then for(int i = n-1; i \>= 0; i--). Additionally, for unsigned the second for won't even work, and the first for is one of the easiest ways I've seen it written for unsigned.For example for(size\_t i = n; i--\>0;) 2022-11-08T21:16:37.72Z+00:00 7 Reply - Copy link [![](https://i.sstatic.net/oOG5XEA4.jpg?s=64)](https://stackoverflow.com/users/236757/baldrunner2049) baldrunner2049 [baldrunner2049](https://stackoverflow.com/users/236757/baldrunner2049) [Over a year ago](https://stackoverflow.com/questions/1642028/what-is-the-operator-in-c-c#comment138120766_1642035) @MosheBildner well, the more you look at it, IT IS the "downto operator". 2024-04-18T06:58:24.017Z+00:00 6 Reply - Copy link [![](https://www.gravatar.com/avatar/65d10ffe4e06a2318411c324215bc919?s=48&d=identicon&r=PG&f=y&so-version=2)](https://stackoverflow.com/users/32266771/tristan-nguyen) Tristan Nguyen [Tristan Nguyen](https://stackoverflow.com/users/32266771/tristan-nguyen) [Jan 27 at 6:06](https://stackoverflow.com/questions/1642028/what-is-the-operator-in-c-c#comment140958795_1642035) Haha, so funny. Such a "confusing" joke 2026-01-27T06:06:18.37Z+00:00 0 Reply - Copy link Add a comment This answer is useful 4064 Save this answer. Show activity on this post. Or for something completely different... `x` slides to `0`. ``` Copy ``` Not so mathematical, but... every picture paints a thousand words... [Share](https://stackoverflow.com/a/8909176 "Short permalink to this answer") Share a link to this answer Copy link [CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/ "The current license for this post: CC BY-SA 4.0") [Improve this answer](https://stackoverflow.com/posts/8909176/edit) Follow Follow this answer to receive notifications [edited Jan 8, 2020 at 22:51](https://stackoverflow.com/posts/8909176/revisions "show all edits to this post") community wiki [8 revs, 8 users 60%](https://stackoverflow.com/posts/8909176/revisions "show revision history for this post") [unsynchronized](https://stackoverflow.com/users/830899) ## 1 Comment Add a comment [![](https://www.gravatar.com/avatar/9b191df60d75770e38bc020226e61ff9?s=48&d=identicon&r=PG&f=y&so-version=2)](https://stackoverflow.com/users/32473980/ana-carolina-de-sousa) Ana Carolina de Sousa [Ana Carolina de Sousa](https://stackoverflow.com/users/32473980/ana-carolina-de-sousa) [Mar 9 at 21:55](https://stackoverflow.com/questions/1642028/what-is-the-operator-in-c-c#comment141006306_8909176) What is the output? is that actually a code? 2026-03-09T21:55:26.563Z+00:00 1 Reply - Copy link This answer is useful 2635 Save this answer. Show activity on this post. That's a very complicated operator, so even [ISO/IEC JTC1 (Joint Technical Committee 1)](https://isocpp.org/std/the-committee) placed its description in two different parts of the C++ Standard. Joking aside, they are two different operators: `--` and `>` described respectively in §5.2.6/2 and §5.9 of the C++03 Standard. [Share](https://stackoverflow.com/a/1642314 "Short permalink to this answer") Share a link to this answer Copy link [CC BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0/ "The current license for this post: CC BY-SA 3.0") [Improve this answer](https://stackoverflow.com/posts/1642314/edit) Follow Follow this answer to receive notifications [edited Oct 2, 2019 at 8:08](https://stackoverflow.com/posts/1642314/revisions "show all edits to this post") community wiki [12 revs, 9 users 31%](https://stackoverflow.com/posts/1642314/revisions "show revision history for this post") [Kirill V. Lyadvinsky](https://stackoverflow.com/users/123111) ## Comments Add a comment This answer is useful 1914 Save this answer. Show activity on this post. `x` can go to zero even faster in the opposite direction in C++: ``` Copy ``` `8 6 4 2` You can control speed with an arrow\! ``` Copy ``` `90 80 70 60 50 40 30 20 10` [Share](https://stackoverflow.com/a/27672749 "Short permalink to this answer") Share a link to this answer Copy link [CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/ "The current license for this post: CC BY-SA 4.0") [Improve this answer](https://stackoverflow.com/posts/27672749/edit) Follow Follow this answer to receive notifications [edited Nov 28, 2025 at 13:14](https://stackoverflow.com/posts/27672749/revisions "show all edits to this post") community wiki [8 revs, 6 users 69%](https://stackoverflow.com/posts/27672749/revisions "show revision history for this post") [mip](https://stackoverflow.com/users/205955) ## 5 Comments Add a comment [![](https://i.sstatic.net/RZLo7.png?s=64)](https://stackoverflow.com/users/584518/lundin) Lundin [Lundin](https://stackoverflow.com/users/584518/lundin) [Over a year ago](https://stackoverflow.com/questions/1642028/what-is-the-operator-in-c-c#comment139787181_27672749) Or you can write `while(0 Donald Duck x)` and that won't compile either. 2024-12-11T15:27:50.147Z+00:00 4 Reply - Copy link [![](https://i.sstatic.net/9kiLH.jpg?s=64)](https://stackoverflow.com/users/205955/mip) mip [mip](https://stackoverflow.com/users/205955/mip) [Over a year ago](https://stackoverflow.com/questions/1642028/what-is-the-operator-in-c-c#comment139791294_27672749) @Lundin how this doesn't compile for you? [coliru.stacked-crooked.com/a/8cb91ccb51dff724](https://coliru.stacked-crooked.com/a/8cb91ccb51dff724) 2024-12-12T09:34:59.297Z+00:00 5 Reply - Copy link [![](https://i.sstatic.net/RZLo7.png?s=64)](https://stackoverflow.com/users/584518/lundin) Lundin [Lundin](https://stackoverflow.com/users/584518/lundin) [Jun 26, 2025 at 9:58](https://stackoverflow.com/questions/1642028/what-is-the-operator-in-c-c#comment140543786_27672749) The result of `--` is not an lvalue and so you can't apply another `--` on top of that because it's operand must be a modifiable lvalue. [godbolt.org/z/s9GbTGezv](https://godbolt.org/z/s9GbTGezv). Specifically, C24 6.5.4.2 *"Prefix increment and decrement operators **Constraints** The operand of the prefix increment or decrement operator shall have atomic, qualified, or unqualified real or pointer type, and shall be a modifiable lvalue.*" 2025-06-26T09:58:43.297Z+00:00 5 Reply - Copy link [![](https://i.sstatic.net/9kiLH.jpg?s=64)](https://stackoverflow.com/users/205955/mip) mip [mip](https://stackoverflow.com/users/205955/mip) [Jun 26, 2025 at 14:22](https://stackoverflow.com/questions/1642028/what-is-the-operator-in-c-c#comment140544610_27672749) Beautiful example how C and C++ differ. Initially we were strongly against mixing C and C++ questions on StackOverflow. 2025-06-26T14:22:07.957Z+00:00 9 Reply - Copy link [![](https://www.gravatar.com/avatar/ad806758c356c915ea08a4bfd79131e3?s=48&d=identicon&r=PG)](https://stackoverflow.com/users/1387438/marek-r) Marek R [Marek R](https://stackoverflow.com/users/1387438/marek-r) [Nov 28, 2025 at 14:11](https://stackoverflow.com/questions/1642028/what-is-the-operator-in-c-c#comment140877653_27672749) [godbolt.org/z/3E7WE1Yj8](https://godbolt.org/z/3E7WE1Yj8) 2025-11-28T14:11:36.603Z+00:00 2 - Copy link Add a comment This answer is useful 1480 Save this answer. \+100 This answer has been awarded bounties worth 100 reputation by Kalana Show activity on this post. It's equivalent to ``` Copywhile (x-- > 0) ``` `x--` (post decrement) is equivalent to `x = x-1` (but returning the original value of `x`), so the code transforms to: ``` Copy ``` [Share](https://stackoverflow.com/a/1642036 "Short permalink to this answer") Share a link to this answer Copy link [CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/ "The current license for this post: CC BY-SA 4.0") [Improve this answer](https://stackoverflow.com/posts/1642036/edit) Follow Follow this answer to receive notifications [edited Jan 22, 2023 at 21:12](https://stackoverflow.com/posts/1642036/revisions "show all edits to this post") community wiki [8 revs, 8 users 38%](https://stackoverflow.com/posts/1642036/revisions "show revision history for this post") [Shubham](https://stackoverflow.com/users/3160529) ## 5 Comments Add a comment [![](https://www.gravatar.com/avatar/e7140b12949e4652885f6bb02b435f42?s=48&d=identicon&r=PG)](https://stackoverflow.com/users/225757/roland-illig) Roland Illig [Roland Illig](https://stackoverflow.com/users/225757/roland-illig) [Over a year ago](https://stackoverflow.com/questions/1642028/what-is-the-operator-in-c-c#comment125230200_1642036) `x--` is in no way equivalent to `x = x-1`. 2022-01-24T17:22:28.363Z+00:00 28 Reply - Copy link [![](https://www.gravatar.com/avatar/9b191df60d75770e38bc020226e61ff9?s=48&d=identicon&r=PG&f=y&so-version=2)](https://stackoverflow.com/users/32473980/ana-carolina-de-sousa) Ana Carolina de Sousa [Ana Carolina de Sousa](https://stackoverflow.com/users/32473980/ana-carolina-de-sousa) [Mar 9 at 21:59](https://stackoverflow.com/questions/1642028/what-is-the-operator-in-c-c#comment141006309_1642036) Actually, both do the same to x, so they are technically equivalent 2026-03-09T21:59:13.5Z+00:00 0 Reply - Copy link [![](https://i.sstatic.net/DsK1y.png?s=64)](https://stackoverflow.com/users/14571585/weston-mcnamara) Weston McNamara [Weston McNamara](https://stackoverflow.com/users/14571585/weston-mcnamara) [Over a year ago](https://stackoverflow.com/questions/1642028/what-is-the-operator-in-c-c#comment126744636_1642036) They're semantically equivalent in this case 2022-04-02T13:52:57.227Z+00:00 12 Reply - Copy link [![](https://www.gravatar.com/avatar/c370c2c0c8358c8b4ad22a081c958951?s=48&d=identicon&r=PG)](https://stackoverflow.com/users/6573544/adola) Adola [Adola](https://stackoverflow.com/users/6573544/adola) [Over a year ago](https://stackoverflow.com/questions/1642028/what-is-the-operator-in-c-c#comment127408838_1642036) `--x` is equivalent to `x = x-1` and `x -=1`. `-1` from me. 2022-05-04T05:38:07.117Z+00:00 6 Reply - Copy link [![](https://www.gravatar.com/avatar/b9ef3fd7c7a963d172a6e789e90aa398?s=48&d=identicon&r=PG&f=y&so-version=2)](https://stackoverflow.com/users/11885241/ofek) Ofek [Ofek](https://stackoverflow.com/users/11885241/ofek) [Over a year ago](https://stackoverflow.com/questions/1642028/what-is-the-operator-in-c-c#comment131141397_1642036) You can say `x--` is equivalent to `(x = x-1) + 1`. 2022-11-01T19:36:17.9Z+00:00 20 Reply - Copy link Add a comment This answer is useful 621 Save this answer. Show activity on this post. It's ``` Copy ``` Just the space makes the things look funny, `--` decrements and `>` compares. [Share](https://stackoverflow.com/a/1642037 "Short permalink to this answer") Share a link to this answer Copy link [CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/ "The current license for this post: CC BY-SA 4.0") [Improve this answer](https://stackoverflow.com/posts/1642037/edit) Follow Follow this answer to receive notifications [edited Jan 1, 2024 at 22:38](https://stackoverflow.com/posts/1642037/revisions "show all edits to this post") community wiki [8 revs, 8 users 44%](https://stackoverflow.com/posts/1642037/revisions "show revision history for this post") [RageZ](https://stackoverflow.com/users/169442) ## Comments Add a comment This answer is useful 508 Save this answer. Show activity on this post. The usage of `-->` has historical relevance. Decrementing was (and still is in some cases), faster than incrementing on the x86 architecture. Using `-->` suggests that `x` is going to `0`, and appeals to those with mathematical backgrounds. [Share](https://stackoverflow.com/a/1755737 "Short permalink to this answer") Share a link to this answer Copy link [CC BY-SA 2.5](https://creativecommons.org/licenses/by-sa/2.5/ "The current license for this post: CC BY-SA 2.5") [Improve this answer](https://stackoverflow.com/posts/1755737/edit) Follow Follow this answer to receive notifications answered [Nov 18, 2009 at 12:47](https://stackoverflow.com/posts/1755737/revisions "show all edits to this post") community wiki [Matt Joiner](https://stackoverflow.com/posts/1755737/revisions "show revision history for this post") ## 6 Comments Add a comment [![](https://www.gravatar.com/avatar/812ca59496d357b8a2ae5636f6d42f8b?s=48&d=identicon&r=PG)](https://stackoverflow.com/users/127380/burito) burito [burito](https://stackoverflow.com/users/127380/burito) [Over a year ago](https://stackoverflow.com/questions/1642028/what-is-the-operator-in-c-c#comment1893791_1755737) Not exactly true. Decrementing and Incrementing take the same amount of time, the benefit of this is that comparison to zero is very fast compared to comparison versus a variable. This is true for many architectures, not just x86. Anything with a JZ instruction (jump if zero). Poking around you can find many "for" loops that are written backwards to save cycles on the compare. This is particularly fast on x86 as the act of decrementing the variable set the zero flag appropriately, so you could then branch without having to explicitly compare the variable. 2009-12-30T05:16:46.543Z+00:00 585 Reply - Copy link [![](https://www.gravatar.com/avatar/1355030928a7422efe6349a3ae9bca83?s=48&d=identicon&r=PG)](https://stackoverflow.com/users/149391/joey-adams) Joey Adams [Joey Adams](https://stackoverflow.com/users/149391/joey-adams) [Over a year ago](https://stackoverflow.com/questions/1642028/what-is-the-operator-in-c-c#comment2635483_1755737) Well, decrementing toward zero means you only have to compare against 0 per loop iteration, while iterating toward n means comparing with n each iteration. The former tends to be easier (and on some architectures, is automatically tested after every data register operation). 2010-04-12T15:07:58.783Z+00:00 46 Reply - Copy link [![](https://i.sstatic.net/0tsJk.jpg?s=64)](https://stackoverflow.com/users/1156377/mark-k-cowan) Mark K Cowan [Mark K Cowan](https://stackoverflow.com/users/1156377/mark-k-cowan) [Over a year ago](https://stackoverflow.com/questions/1642028/what-is-the-operator-in-c-c#comment50573467_1755737) In x86 ASM, the `LOOP <address>` decreases the `ECX` register, then jumps to `<address>` unless the decrementing of `ECX` resulted in zero. Decrementing the loop counter towards zero allows the compiler to generate a single `LOOP` instruction, whereas incrementing or counting to other values requires separate INC/DEC/ADD/SUB, compare, and conditional jump instructions. Modern compilers can often convert other loops to a `counter --> 0` loop if the value of `counter` isn't used in the loop. 2015-07-08T11:26:58.503Z+00:00 14 Reply - Copy link [![](https://i.sstatic.net/0tsJk.jpg?s=64)](https://stackoverflow.com/users/1156377/mark-k-cowan) Mark K Cowan [Mark K Cowan](https://stackoverflow.com/users/1156377/mark-k-cowan) [Over a year ago](https://stackoverflow.com/questions/1642028/what-is-the-operator-in-c-c#comment50573707_1755737) Continuing my previous comment: `MOV ECX, value`, `@start:`, `<code>`, `LOOP @start` is an x86 ASM equivalent for `counter = value - 1; while (counter --> 0) { <code>; }`. Note that it will barf if `value` is initially zero, so an extra check is needed pre-loop. 2015-07-08T11:32:17.677Z+00:00 7 Reply - Copy link [![](https://www.gravatar.com/avatar/da3b47c80b3c9d6f9e37a88b2ca51e6a?s=48&d=identicon&r=PG)](https://stackoverflow.com/users/1303846/remember-monica) Remember Monica [Remember Monica](https://stackoverflow.com/users/1303846/remember-monica) [Over a year ago](https://stackoverflow.com/questions/1642028/what-is-the-operator-in-c-c#comment126734567_1755737) LOOP was never particularly fast, though. 2022-04-01T18:48:12.937Z+00:00 5 Reply - Copy link Add a comment \| Show 1 more comment This answer is useful 447 Save this answer. Show activity on this post. Utterly geek, but I will be using this: ``` Copy ``` [Share](https://stackoverflow.com/a/2860927 "Short permalink to this answer") Share a link to this answer Copy link [CC BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0/ "The current license for this post: CC BY-SA 3.0") [Improve this answer](https://stackoverflow.com/posts/2860927/edit) Follow Follow this answer to receive notifications [edited Dec 3, 2011 at 2:33](https://stackoverflow.com/posts/2860927/revisions "show all edits to this post") community wiki [3 revs, 2 users 76% Arrieta](https://stackoverflow.com/posts/2860927/revisions "show revision history for this post") ## 3 Comments Add a comment [![](https://www.gravatar.com/avatar/404105c1a345256082b0d2fa360226f9?s=48&d=identicon&r=PG)](https://stackoverflow.com/users/1839838/stevepoling) StevePoling [StevePoling](https://stackoverflow.com/users/1839838/stevepoling) [Over a year ago](https://stackoverflow.com/questions/1642028/what-is-the-operator-in-c-c#comment117595391_2860927) I know it looks way cool, but I fear it's deceptive. The reason you're writing C++ instead of Machine Language is b/c you want to convey your intent to the next guy reading your code. This construct violates the principle of least surprise. It is a mental "trip hazard." 2021-03-07T19:43:19.757Z+00:00 26 Reply - Copy link [![](https://www.gravatar.com/avatar/e7140b12949e4652885f6bb02b435f42?s=48&d=identicon&r=PG)](https://stackoverflow.com/users/225757/roland-illig) Roland Illig [Roland Illig](https://stackoverflow.com/users/225757/roland-illig) [Over a year ago](https://stackoverflow.com/questions/1642028/what-is-the-operator-in-c-c#comment125230234_2860927) Calling `atoi` makes the code smell immediately. 2022-01-24T17:24:08.337Z+00:00 6 Reply - Copy link [![](https://i.sstatic.net/UYbz6.jpg?s=64)](https://stackoverflow.com/users/5849965/friskysaga) FriskySaga [FriskySaga](https://stackoverflow.com/users/5849965/friskysaga) [Over a year ago](https://stackoverflow.com/questions/1642028/what-is-the-operator-in-c-c#comment131901914_2860927) @StevePoling Intent is being communicated. When I read this code, I understand that I am being trolled. 2022-12-08T20:06:26.987Z+00:00 39 Reply - Copy link Add a comment This answer is useful 382 Save this answer. Show activity on this post. One book I read (I don't remember correctly which book) stated: **Compilers try to parse expressions to the biggest token** by using the left right rule. In this case, the expression: ``` Copyx-->0 ``` Parses to biggest tokens: ``` token 1: x token 2: -- token 3: > token 4: 0 conclude: x-- > 0 ``` **The same rule** applies to this expression: ``` Copya-----b ``` After parse: ``` token 1: a token 2: -- token 3: -- token 4: - token 5: b conclude: (a--)-- - b ``` [Share](https://stackoverflow.com/a/2604267 "Short permalink to this answer") Share a link to this answer Copy link [CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/ "The current license for this post: CC BY-SA 4.0") [Improve this answer](https://stackoverflow.com/posts/2604267/edit) Follow Follow this answer to receive notifications [edited Oct 8, 2023 at 15:46](https://stackoverflow.com/posts/2604267/revisions "show all edits to this post") community wiki [7 revs, 6 users 54%](https://stackoverflow.com/posts/2604267/revisions "show revision history for this post") [NguyenDat](https://stackoverflow.com/users/3941732) ## Comments Add a comment This answer is useful 306 Save this answer. Show activity on this post. This is exactly the same as `while(x--)` for non-negative numbers. [Share](https://stackoverflow.com/a/1985476 "Short permalink to this answer") Share a link to this answer Copy link [CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/ "The current license for this post: CC BY-SA 4.0") [Improve this answer](https://stackoverflow.com/posts/1985476/edit) Follow Follow this answer to receive notifications [edited Mar 7, 2024 at 21:24](https://stackoverflow.com/posts/1985476/revisions "show all edits to this post") community wiki [6 revs, 5 users 35%](https://stackoverflow.com/posts/1985476/revisions "show revision history for this post") [Jan Schultke](https://stackoverflow.com/users/5740428) ## 5 Comments Add a comment [![](https://graph.facebook.com/1042922965/picture?type=large)](https://stackoverflow.com/users/3991211/geoduck) Geoduck [Geoduck](https://stackoverflow.com/users/3991211/geoduck) [Over a year ago](https://stackoverflow.com/questions/1642028/what-is-the-operator-in-c-c#comment136732771_1985476) unless x is negative... 2023-11-27T19:55:16.753Z+00:00 1 Reply - Copy link [![](https://www.gravatar.com/avatar/b6560fe552aeba1f1c4ed4d088d24419?s=48&d=identicon&r=PG&f=y&so-version=2)](https://stackoverflow.com/users/3150445/jwdonahue) jwdonahue [jwdonahue](https://stackoverflow.com/users/3150445/jwdonahue) [Over a year ago](https://stackoverflow.com/questions/1642028/what-is-the-operator-in-c-c#comment137137811_1985476) It really doesn't matter if x starts positive or negative, it will eventually reach zero. 2024-01-10T01:30:35.16Z+00:00 1 Reply - Copy link [![](https://www.gravatar.com/avatar/131c67ef492a8d8352c6cf642a52e20f?s=48&d=identicon&r=PG)](https://stackoverflow.com/users/1505939/m-m) M.M [M.M](https://stackoverflow.com/users/1505939/m-m) [Over a year ago](https://stackoverflow.com/questions/1642028/what-is-the-operator-in-c-c#comment137377359_1985476) @jwdonahue it will cause undefined behaviour if `x` starts negative, due to signed integer overflow 2024-02-02T03:19:50.51Z+00:00 4 Reply - Copy link [![](https://www.gravatar.com/avatar/b6560fe552aeba1f1c4ed4d088d24419?s=48&d=identicon&r=PG&f=y&so-version=2)](https://stackoverflow.com/users/3150445/jwdonahue) jwdonahue [jwdonahue](https://stackoverflow.com/users/3150445/jwdonahue) [Over a year ago](https://stackoverflow.com/questions/1642028/what-is-the-operator-in-c-c#comment137377672_1985476) @M.M I couldn't find that in my old C-11 draft. My recall may not be what it once was, but I am fairly sure that I have relied on integer decrement/increment wrapping around on more than one occasion in the past (DAC wave form generation). Haven't worked in C/C++ much these past 12 years though. Could you point us towards the standards language supporting your claim? 2024-02-02T04:38:28.153Z+00:00 0 Reply - Copy link [![](https://www.gravatar.com/avatar/131c67ef492a8d8352c6cf642a52e20f?s=48&d=identicon&r=PG)](https://stackoverflow.com/users/1505939/m-m) M.M [M.M](https://stackoverflow.com/users/1505939/m-m) [Over a year ago](https://stackoverflow.com/questions/1642028/what-is-the-operator-in-c-c#comment137387408_1985476) @jwdonahue see [stackoverflow.com/a/41280273/1505939](https://stackoverflow.com/a/41280273/1505939) for Standard quotes 2024-02-02T23:07:18.887Z+00:00 2 Reply - Copy link Add a comment This answer is useful 268 Save this answer. Show activity on this post. Anyway, we have a "goes to" operator now. `"-->"` is easy to be remembered as a direction, and "while x goes to zero" is meaning-straight. Furthermore, it is a little more efficient than `"for (x = 10; x > 0; x --)"` on some platforms. [Share](https://stackoverflow.com/a/1644241 "Short permalink to this answer") Share a link to this answer Copy link [CC BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0/ "The current license for this post: CC BY-SA 3.0") [Improve this answer](https://stackoverflow.com/posts/1644241/edit) Follow Follow this answer to receive notifications [edited Feb 28, 2013 at 17:28](https://stackoverflow.com/posts/1644241/revisions "show all edits to this post") community wiki [4 revs, 3 users 56%](https://stackoverflow.com/posts/1644241/revisions "show revision history for this post") [Test](https://stackoverflow.com/users/187646) ## 11 Comments Add a comment [![](https://www.gravatar.com/avatar/203ce089d850f900da759839ccfefdd2?s=48&d=identicon&r=PG)](https://stackoverflow.com/users/201633/ganesh-gopalasubramanian) Ganesh Gopalasubramanian [Ganesh Gopalasubramanian](https://stackoverflow.com/users/201633/ganesh-gopalasubramanian) [Over a year ago](https://stackoverflow.com/questions/1642028/what-is-the-operator-in-c-c#comment1606141_1644241) Goes to cant be true always especially when value of x is negative. 2009-11-13T03:22:41.113Z+00:00 27 Reply - Copy link [![](https://www.gravatar.com/avatar/2180b1a962bf46e58fa9746cb4ebfb91?s=48&d=identicon&r=PG)](https://stackoverflow.com/users/1527/pete-kirkham) Pete Kirkham [Pete Kirkham](https://stackoverflow.com/users/1527/pete-kirkham) [Over a year ago](https://stackoverflow.com/questions/1642028/what-is-the-operator-in-c-c#comment3160075_1644241) The other version does not do the same thing - with `for (size_t x=10; x-->0; )` the body of the loop is executed with 9,8,..,0 whereas the other version has 10,9,..,1. It's quite tricky to exit a loop down to zero with an unsigned variable otherwise. 2010-06-21T08:57:44.143Z+00:00 22 Reply - Copy link [![](https://www.gravatar.com/avatar/79dd751f512eabafb2c48f08f735a2de?s=48&d=identicon&r=PG)](https://stackoverflow.com/users/1147061/tslmy) tslmy [tslmy](https://stackoverflow.com/users/1147061/tslmy) [Over a year ago](https://stackoverflow.com/questions/1642028/what-is-the-operator-in-c-c#comment24771663_1644241) I think this is a little bit misleading... We don't have a literally "goes to" operator, since we need another `++>` to do the incremental work. 2013-06-15T02:49:10.983Z+00:00 9 Reply - Copy link [![](https://www.gravatar.com/avatar/165e55c78689e561c554c3dec671fb50?s=48&d=identicon&r=PG)](https://stackoverflow.com/users/294313/samb) SamB [SamB](https://stackoverflow.com/users/294313/samb) [Over a year ago](https://stackoverflow.com/questions/1642028/what-is-the-operator-in-c-c#comment30494802_1644241) @Josh: actually, overflow gives undefined behavior for `int`, so it could just as easily eat your dog as take `x` to zero if it starts out negative. 2013-12-06T06:57:56.927Z+00:00 27 Reply - Copy link [![](https://www.gravatar.com/avatar/2a4b86c1c90bc06112c2c069b58bf995?s=48&d=identicon&r=PG)](https://stackoverflow.com/users/1436796/marc-van-leeuwen) Marc van Leeuwen [Marc van Leeuwen](https://stackoverflow.com/users/1436796/marc-van-leeuwen) [Over a year ago](https://stackoverflow.com/questions/1642028/what-is-the-operator-in-c-c#comment39963532_1644241) This is a very important idiom to me for the reason given in the comnmet by @PeteKirkham, as I often need to do decreasing loops over unsigned quantities all the way to `0`. (For comparison, the idiom of omitting tests for zero, such as writing `while (n--)` instead for unsigned `n`, buys you nothing and for me greatly hampers readability.) It also has the pleasant property that you specify *one more* than the initial index, which is usually what you want (e.g., for a loop over an array you specify its size). I also like `-->` without space, as this makes the idiom easy to recognise. 2014-08-30T20:08:39.37Z+00:00 5 Reply - Copy link Add a comment \| Show 6 more comments This answer is useful 244 Save this answer. Show activity on this post. This code first compares x and 0 and then decrements x. (Also said in the first answer: You're post-decrementing x and then comparing x and 0 with the `>` operator.) See the output of this code: ``` 9 8 7 6 5 4 3 2 1 0 ``` We now first compare and then decrement by seeing 0 in the output. If we want to first decrement and then compare, use this code: ``` Copy ``` That output is: ``` 9 8 7 6 5 4 3 2 1 ``` [Share](https://stackoverflow.com/a/1755774 "Short permalink to this answer") Share a link to this answer Copy link [CC BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0/ "The current license for this post: CC BY-SA 3.0") [Improve this answer](https://stackoverflow.com/posts/1755774/edit) Follow Follow this answer to receive notifications [edited Jan 3, 2016 at 17:48](https://stackoverflow.com/posts/1755774/revisions "show all edits to this post") community wiki [5 revs, 4 users 70%](https://stackoverflow.com/posts/1755774/revisions "show revision history for this post") [SjB](https://stackoverflow.com/users/140934) ## Comments Add a comment This answer is useful 201 Save this answer. Show activity on this post. My compiler will print out 9876543210 when I run this code. ``` Copy ``` As expected. The `while( x-- > 0 )` actually means `while( x > 0)`. The `x--` post decrements `x`. ``` Copy ``` is a different way of writing the same thing. It is nice that the original looks like "while x goes to 0" though. [Share](https://stackoverflow.com/a/2079545 "Short permalink to this answer") Share a link to this answer Copy link [CC BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0/ "The current license for this post: CC BY-SA 3.0") [Improve this answer](https://stackoverflow.com/posts/2079545/edit) Follow Follow this answer to receive notifications [edited Apr 30, 2015 at 22:49](https://stackoverflow.com/posts/2079545/revisions "show all edits to this post") community wiki [5 revs, 4 users 82%](https://stackoverflow.com/posts/2079545/revisions "show revision history for this post") [cool\_me5000](https://stackoverflow.com/users/248662) ## 3 Comments Add a comment [![](https://i.sstatic.net/mzB6K.jpg?s=64)](https://stackoverflow.com/users/390876/tim-leaf) Tim Leaf [Tim Leaf](https://stackoverflow.com/users/390876/tim-leaf) [Over a year ago](https://stackoverflow.com/questions/1642028/what-is-the-operator-in-c-c#comment2808440_2079545) The result is only undefined when you're incrementing/decrementing the same variable more than once in the same statement. It doesn't apply to this situation. 2010-05-05T15:30:19.063Z+00:00 6 Reply - Copy link [![](https://i.sstatic.net/6pRI7.png?s=64)](https://stackoverflow.com/users/1711796/bernhard-barker) Bernhard Barker [Bernhard Barker](https://stackoverflow.com/users/1711796/bernhard-barker) [Over a year ago](https://stackoverflow.com/questions/1642028/what-is-the-operator-in-c-c#comment48881153_2079545) `while( x-- > 0 ) actually means while( x > 0)` - I'm not sure what you were trying to say there, but the way you phrased it implies the `--` has no meaning whatsoever, which is obviously very wrong. 2015-05-22T12:28:30.97Z+00:00 18 Reply - Copy link [![](https://www.gravatar.com/avatar/5fd80d98f96f9adbde7876cbda181715?s=48&d=identicon&r=PG)](https://stackoverflow.com/users/364818/mark-lakata) Mark Lakata [Mark Lakata](https://stackoverflow.com/users/364818/mark-lakata) [Over a year ago](https://stackoverflow.com/questions/1642028/what-is-the-operator-in-c-c#comment106811657_2079545) To drive the point home from @Dukeling, this answer is *not the same* as the original post. In the original post, `x` will be `-1` after it leaves the loop, while in this answer, `x` will be `0`. 2020-02-24T16:41:38.21Z+00:00 3 Reply - Copy link Add a comment This answer is useful 169 Save this answer. Show activity on this post. There is a space missing between `--` and `>`. `x` is post decremented, that is, decremented after checking the condition `x>0 ?`. [Share](https://stackoverflow.com/a/1970277 "Short permalink to this answer") Share a link to this answer Copy link [CC BY-SA 2.5](https://creativecommons.org/licenses/by-sa/2.5/ "The current license for this post: CC BY-SA 2.5") [Improve this answer](https://stackoverflow.com/posts/1970277/edit) Follow Follow this answer to receive notifications [edited Nov 22, 2010 at 19:02](https://stackoverflow.com/posts/1970277/revisions "show all edits to this post") community wiki [2 revs, 2 users 50% Mr. X](https://stackoverflow.com/posts/1970277/revisions "show revision history for this post") ## 3 Comments Add a comment user529758 user529758 [Over a year ago](https://stackoverflow.com/questions/1642028/what-is-the-operator-in-c-c#comment15653586_1970277) The space is not missing - C(++) ignores whitespace. 2012-08-02T19:16:31.373Z+00:00 51 Reply - Copy link [![](https://www.gravatar.com/avatar/75ee864ee3bef78f2a144398789fed25?s=48&d=identicon&r=PG)](https://stackoverflow.com/users/648658/jens) Jens [Jens](https://stackoverflow.com/users/648658/jens) [Over a year ago](https://stackoverflow.com/questions/1642028/what-is-the-operator-in-c-c#comment23206308_1970277) @H2CO3 This isn't true in general. There are places where white space must be used to separate tokens, e.g. in `#define foo()` versus `#define foo ()`. 2013-04-25T21:16:44.457Z+00:00 33 Reply - Copy link [![](https://www.gravatar.com/avatar/086a78b98e9d1fe37cd492dd25e42c34?s=48&d=identicon&r=PG)](https://stackoverflow.com/users/733805/kevin-p-rice) Kevin P. Rice [Kevin P. Rice](https://stackoverflow.com/users/733805/kevin-p-rice) [Over a year ago](https://stackoverflow.com/questions/1642028/what-is-the-operator-in-c-c#comment30437937_1970277) @Jens How about: "The space is not missing - C(++) ignores unnecessary white space."? 2013-12-04T20:35:14.183Z+00:00 35 Reply - Copy link Add a comment This answer is useful 158 Save this answer. Show activity on this post. `--` is the **decrement** operator and `>` is the **greater-than** operator. The two operators are applied as a single one like `-->`. [Share](https://stackoverflow.com/a/2584185 "Short permalink to this answer") Share a link to this answer Copy link [CC BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0/ "The current license for this post: CC BY-SA 3.0") [Improve this answer](https://stackoverflow.com/posts/2584185/edit) Follow Follow this answer to receive notifications [edited Oct 29, 2011 at 21:42](https://stackoverflow.com/posts/2584185/revisions "show all edits to this post") community wiki [4 revs, 4 users 38%](https://stackoverflow.com/posts/2584185/revisions "show revision history for this post") [muntoo](https://stackoverflow.com/users/365102) ## 1 Comment Add a comment [![](https://www.gravatar.com/avatar/b70cbba438368bb424ba5c02eb2711a9?s=48&d=identicon&r=PG&f=y&so-version=2)](https://stackoverflow.com/users/2757035/underscore-d) underscore\_d [underscore\_d](https://stackoverflow.com/users/2757035/underscore-d) [Over a year ago](https://stackoverflow.com/questions/1642028/what-is-the-operator-in-c-c#comment68368582_2584185) They're *applied* as the 2 separate operators they are. They're only *written* misleadingly to look like "a single one". 2016-11-12T17:56:09.313Z+00:00 21 Reply - Copy link This answer is useful 155 Save this answer. Show activity on this post. It's a combination of two operators. First `--` is for decrementing the value, and `>` is for checking whether the value is greater than the right-hand operand. ``` Copy ``` The output will be: ``` 9 8 7 6 5 4 3 2 1 0 ``` [Share](https://stackoverflow.com/a/15762842 "Short permalink to this answer") Share a link to this answer Copy link [CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/ "The current license for this post: CC BY-SA 4.0") [Improve this answer](https://stackoverflow.com/posts/15762842/edit) Follow Follow this answer to receive notifications [edited Jan 1, 2024 at 22:39](https://stackoverflow.com/posts/15762842/revisions "show all edits to this post") community wiki [5 revs, 5 users 45%](https://stackoverflow.com/posts/15762842/revisions "show revision history for this post") [Rajeev Das](https://stackoverflow.com/users/1516804) ## Comments Add a comment This answer is useful 149 Save this answer. Show activity on this post. C and C++ obey the "maximal munch" rule. The same way `a---b` is translated to `(a--) - b`, in your case `x-->0` translates to `(x--)>0`. What the rule says essentially is that going left to right, expressions are formed by taking the maximum of characters which will form a valid token. [Share](https://stackoverflow.com/a/21683994 "Short permalink to this answer") Share a link to this answer Copy link [CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/ "The current license for this post: CC BY-SA 4.0") [Improve this answer](https://stackoverflow.com/posts/21683994/edit) Follow Follow this answer to receive notifications [edited Jan 22, 2022 at 1:46](https://stackoverflow.com/posts/21683994/revisions "show all edits to this post") community wiki [4 revs, 3 users 33%](https://stackoverflow.com/posts/21683994/revisions "show revision history for this post") [Peter Mortensen](https://stackoverflow.com/users/63550) ## 3 Comments Add a comment [![](https://www.gravatar.com/avatar/2bb7485134a4957636621aa28e6f9fae?s=48&d=identicon&r=PG)](https://stackoverflow.com/users/1335492/david) david [david](https://stackoverflow.com/users/1335492/david) [Over a year ago](https://stackoverflow.com/questions/1642028/what-is-the-operator-in-c-c#comment39875221_21683994) Which is what the OP assumed: that "((a)--\>)" was the maximal munch. It turns out that the OP's original assumption was incorrect: "--\>" is not a maximum valid operator. 2014-08-28T00:41:45.467Z+00:00 9 Reply - Copy link [![](https://i.sstatic.net/jfSUmYFd.png?s=64)](https://stackoverflow.com/users/163227/roy-tinker) Roy Tinker [Roy Tinker](https://stackoverflow.com/users/163227/roy-tinker) [Over a year ago](https://stackoverflow.com/questions/1642028/what-is-the-operator-in-c-c#comment50687455_21683994) Also known as greedy parsing, if I recall correctly. 2015-07-11T01:04:15.21Z+00:00 4 Reply - Copy link [![](https://www.gravatar.com/avatar/5cfe5f7d64f44be04f147295f5c7b88e?s=48&d=identicon&r=PG)](https://stackoverflow.com/users/207421/user207421) user207421 [user207421](https://stackoverflow.com/users/207421/user207421) [Over a year ago](https://stackoverflow.com/questions/1642028/what-is-the-operator-in-c-c#comment66187719_21683994) @RoyTinker Greedy *scanning.* The parser has nothing to do with this. 2016-09-11T02:21:50.067Z+00:00 3 Reply - Copy link Add a comment This answer is useful 138 Save this answer. Show activity on this post. Actually, `x` is post-decrementing and with that condition is being checked. It's not `-->`, it's `(x--) > 0` Note: value of `x` is changed after the condition is checked, because it post-decrementing. Some similar cases can also occur, for example: ``` Copy ``` [Share](https://stackoverflow.com/a/12016806 "Short permalink to this answer") Share a link to this answer Copy link [CC BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0/ "The current license for this post: CC BY-SA 3.0") [Improve this answer](https://stackoverflow.com/posts/12016806/edit) Follow Follow this answer to receive notifications [edited Apr 12, 2014 at 9:52](https://stackoverflow.com/posts/12016806/revisions "show all edits to this post") community wiki [3 revs, 3 users 70%](https://stackoverflow.com/posts/12016806/revisions "show revision history for this post") [AndroidLearner](https://stackoverflow.com/users/1479075) ## 2 Comments Add a comment [![](https://i.sstatic.net/okH8Y.jpg?s=64)](https://stackoverflow.com/users/3450840/florian-f) Florian F [Florian F](https://stackoverflow.com/users/3450840/florian-f) [Over a year ago](https://stackoverflow.com/questions/1642028/what-is-the-operator-in-c-c#comment39994228_12016806) Except that ++\> can hardly be used in a while(). A "goes up to..." operator would be ++\<, which doesn't look anywhere as nice. The operator --\> is a happy coincidence. 2014-09-01T09:46:25.247Z+00:00 8 Reply - Copy link [![](https://www.gravatar.com/avatar/b70cbba438368bb424ba5c02eb2711a9?s=48&d=identicon&r=PG&f=y&so-version=2)](https://stackoverflow.com/users/2757035/underscore-d) underscore\_d [underscore\_d](https://stackoverflow.com/users/2757035/underscore-d) [Over a year ago](https://stackoverflow.com/questions/1642028/what-is-the-operator-in-c-c#comment68368604_12016806) @BenLeggiero That could 'work' in the sense of generating code that does something (while infuriating readers who don't like faux-clever code), but the semantics are different, as its use of predecrement means it will execute one fewer iteration. As a contrived example, it would never execute the loop body if `x` started at 1, but `while ( (x--) > 0 )` would. {edit} Eric Lippert covered both in his C\# 4 release notes: [blogs.msdn.microsoft.com/ericlippert/2010/04/01/…](https://blogs.msdn.microsoft.com/ericlippert/2010/04/01/some-last-minute-new-c-4-0-features/) 2016-11-12T17:57:29.713Z+00:00 2 Reply - Copy link This answer is useful 82 Save this answer. Show activity on this post. Instead of regular arrow operator (--\>) you can use armor-piercing arrow operator: --x\> (note those sharp barbs on the arrow tip). It adds +1 to armor piercing, so it finishes the loop 1 iteration faster than regular arrow operator. Try it yourself: ``` Copy ``` [Share](https://stackoverflow.com/a/67828001 "Short permalink to this answer") Share a link to this answer Copy link [CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/ "The current license for this post: CC BY-SA 4.0") [Improve this answer](https://stackoverflow.com/posts/67828001/edit) Follow Follow this answer to receive notifications [edited Aug 25, 2023 at 21:32](https://stackoverflow.com/posts/67828001/revisions "show all edits to this post") community wiki [2 revs, 2 users 67%](https://stackoverflow.com/posts/67828001/revisions "show revision history for this post") [hydrechan](https://stackoverflow.com/users/1091474) ## 2 Comments Add a comment [![](https://i.sstatic.net/E9ThY.png?s=64)](https://stackoverflow.com/users/2057171/albert-renshaw) Albert Renshaw [Albert Renshaw](https://stackoverflow.com/users/2057171/albert-renshaw) [Over a year ago](https://stackoverflow.com/questions/1642028/what-is-the-operator-in-c-c#comment125936646_67828001) Don't forget about the `Extra Long Arrow` operator which moves twice as fast, `x ----> 0` 2022-02-24T02:58:18.273Z+00:00 17 Reply - Copy link [![](https://graph.facebook.com/2743998582293894/picture?type=large)](https://stackoverflow.com/users/11497165/cyee) cYee [cYee](https://stackoverflow.com/users/11497165/cyee) [Over a year ago](https://stackoverflow.com/questions/1642028/what-is-the-operator-in-c-c#comment131896601_67828001) and the `Extra Long Armor Piercing Arrow` operator, `----x> 0` for your fast piercing 2022-12-08T15:26:24.963Z+00:00 12 Reply - Copy link This answer is useful 37 Save this answer. Show activity on this post. The simple answer to the original question is that the following code does the same thing (though I am not saying you should do it like this): ``` Copy ``` The `x--` is just shorthand for the above, and `>` is just a normal greater-than `operator`. [Share](https://stackoverflow.com/a/40288213 "Short permalink to this answer") Share a link to this answer Copy link [CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/ "The current license for this post: CC BY-SA 4.0") [Improve this answer](https://stackoverflow.com/posts/40288213/edit) Follow Follow this answer to receive notifications [edited Oct 8, 2023 at 12:09](https://stackoverflow.com/posts/40288213/revisions "show all edits to this post") community wiki [6 revs, 5 users 58%](https://stackoverflow.com/posts/40288213/revisions "show revision history for this post") [Garry\_G](https://stackoverflow.com/users/3660147) ## 5 Comments Add a comment [![](https://i.sstatic.net/7iZSI.png?s=64)](https://stackoverflow.com/users/777716/pix) pix [pix](https://stackoverflow.com/users/777716/pix) [Over a year ago](https://stackoverflow.com/questions/1642028/what-is-the-operator-in-c-c#comment67835530_40288213) This question is not about complications, but about \*\* Hidden Features and Dark Corners of C++/STL\*\* 2016-10-27T15:32:01.917Z+00:00 22 Reply - Copy link [![](https://i.sstatic.net/ZpqMk.png?s=64)](https://stackoverflow.com/users/528720/%C3%96%C3%B6-tiib) Öö Tiib [Öö Tiib](https://stackoverflow.com/users/528720/%C3%96%C3%B6-tiib) [Over a year ago](https://stackoverflow.com/questions/1642028/what-is-the-operator-in-c-c#comment74934593_40288213) The program here gives different output than original because x here is decremented after printf. That demonstrates well how "simple answers" are usually Incorrect. 2017-05-13T09:30:30.263Z+00:00 29 Reply - Copy link [![](https://www.gravatar.com/avatar/3056c5185987f1265aca9235680a0bcd?s=48&d=identicon&r=PG)](https://stackoverflow.com/users/1030576/anthony) Anthony [Anthony](https://stackoverflow.com/users/1030576/anthony) [Over a year ago](https://stackoverflow.com/questions/1642028/what-is-the-operator-in-c-c#comment82639767_40288213) `The OP's way: 9 8 7 6 5 4 3 2 1 0` and `The Garry_G way: 10 9 8 7 6 5 4 3 2 1` 2017-12-15T18:33:22.093Z+00:00 3 Reply - Copy link [![](https://www.gravatar.com/avatar/e113b0a68eb6a474bd9533fba3fbf956?s=48&d=identicon&r=PG)](https://stackoverflow.com/users/201751/citbl) CITBL [CITBL](https://stackoverflow.com/users/201751/citbl) [Over a year ago](https://stackoverflow.com/questions/1642028/what-is-the-operator-in-c-c#comment94942667_40288213) It doesn't do the same thing. Move your `x=x-1` before `printf` then you can say "it does the same thing". 2019-01-05T17:05:49.73Z+00:00 4 Reply - Copy link [![](https://www.gravatar.com/avatar/c13f613a9c830b032569eed94ae98363?s=48&d=identicon&r=PG)](https://stackoverflow.com/users/14667736/wolfram-r%C3%B6sler) Wolfram Rösler [Wolfram Rösler](https://stackoverflow.com/users/14667736/wolfram-r%C3%B6sler) [Over a year ago](https://stackoverflow.com/questions/1642028/what-is-the-operator-in-c-c#comment123746085_40288213) I agree with your attitude about simple and complicated, however `x=x-1` is definitely more complicated than `x--` (more characters to type, harder to read because people wonder why you're not just using good old `x--`, etc.) Also, C programmers who consider things like side effects in `while` to be overly complicated tend to make me suspicious. 2021-11-17T11:06:44.227Z+00:00 1 Reply - Copy link Add a comment This answer is useful 34 Save this answer. Show activity on this post. Conventional way we define condition in while loop parenthesis"`()`" and terminating condition inside the braces"`{}`", but this `--` & `>` is a way one defines all at once. For example: ``` Copy ``` It says, decrement `a` and run the loop till the time `a` is greater than `0` Other way it should have been like: ``` Copy ``` Both ways, we do the same thing and achieve the same goals. [Share](https://stackoverflow.com/a/44231561 "Short permalink to this answer") Share a link to this answer Copy link [CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/ "The current license for this post: CC BY-SA 4.0") [Improve this answer](https://stackoverflow.com/posts/44231561/edit) Follow Follow this answer to receive notifications [edited Dec 30, 2020 at 17:46](https://stackoverflow.com/posts/44231561/revisions "show all edits to this post") community wiki [4 revs, 4 users 56%](https://stackoverflow.com/posts/44231561/revisions "show revision history for this post") [Zohaib Ejaz](https://stackoverflow.com/users/7549913) ## 3 Comments Add a comment [![](https://i.sstatic.net/WMdEs.png?s=64)](https://stackoverflow.com/users/2893496/v010dya) v010dya [v010dya](https://stackoverflow.com/users/2893496/v010dya) [Over a year ago](https://stackoverflow.com/questions/1642028/what-is-the-operator-in-c-c#comment77191592_44231561) This is incorrect. The code in the question does: 'test-write-execute' (test first, write new value, execute the loop), your example is 'test-execute-write'. 2017-07-14T19:07:40.67Z+00:00 6 Reply - Copy link [![](https://i.sstatic.net/kOMLd.png?s=64)](https://stackoverflow.com/users/3314225/stefan-fabian) Stefan Fabian [Stefan Fabian](https://stackoverflow.com/users/3314225/stefan-fabian) [Over a year ago](https://stackoverflow.com/questions/1642028/what-is-the-operator-in-c-c#comment115783865_44231561) @S.S.Anne Your edit is still wrong. The `a--` after the while shouldn't be there. 2020-12-29T09:49:32.077Z+00:00 0 Reply - Copy link [![](https://i.sstatic.net/EEyLy.jpg?s=64)](https://stackoverflow.com/users/4593267/chqrlie) chqrlie [chqrlie](https://stackoverflow.com/users/4593267/chqrlie) [Over a year ago](https://stackoverflow.com/questions/1642028/what-is-the-operator-in-c-c#comment117732228_44231561) *Both ways, we do the same thing and achieve the same goals.* Not really: both loops iterate 5 times, but the final value of `a` after the loop completes is `-1` in the first case and `0` in the second. 2021-03-12T12:20:33.807Z+00:00 0 Reply - Copy link Add a comment This answer is useful 33 Save this answer. Show activity on this post. `(x --> 0)` means `(x-- > 0)`. 1. You can use `(x -->)` `Output: 9 8 7 6 5 4 3 2 1 0` 1. You can use `(-- x > 0)` It's mean `(--x > 0)` `Output: 9 8 7 6 5 4 3 2 1` 1. You can use ``` Copy ``` `Output: 9 8 7 6 5 4 3 2 1` 1. You can use ``` Copy ``` `Output: 9 8 7 6 5 4 3 2 1 0` 1. You can use ``` Copy ``` `Output: 9 8 7 6 5 4 3 2 1 0` 1. You can use also ``` Copy ``` `Output: 9 8 7 6 5 4 3 2 1 0` Likewise, you can try lot of methods to execute this command successfully. [Share](https://stackoverflow.com/a/58062656 "Short permalink to this answer") Share a link to this answer Copy link [CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/ "The current license for this post: CC BY-SA 4.0") [Improve this answer](https://stackoverflow.com/posts/58062656/edit) Follow Follow this answer to receive notifications [edited Oct 28, 2020 at 22:58](https://stackoverflow.com/posts/58062656/revisions "show all edits to this post") community wiki [2 revs, 2 users 87%](https://stackoverflow.com/posts/58062656/revisions "show revision history for this post") [Kalana](https://stackoverflow.com/users/11383441) ## Comments Add a comment This answer is useful 8 Save this answer. Show activity on this post. `-->` is not an operator, it is the juxtaposition of `--` (post-decrement) and `>` (greater than comparison). The loop will look more familiar as: ``` Copy ``` This loop is a classic idiom to enumerate values between `10` (the excluded upper bound) and `0` the included lower bound, useful to iterate over the elements of an array from the last to the first. The initial value `10` is the total number of iterations (for example the length of the array), and one plus the first value used inside the loop. The `0` is the last value of `x` inside the loop, hence the comment *x goes to 0*. Note that the value of `x` after the loop completes is `-1`. Note also that this loop will operate the **same** way if `x` has an **unsigned type** such as `size_t`, which is a strong advantage over the naive alternative `for (i = length-1; i >= 0; i--)`. For this reason, I am actually a fan of this surprising syntax: `while (x --> 0)`. I find this idiom eye-catching and elegant, just like `for (;;)` vs: `while (1)` (which looks confusingly similar to `while (l)`). It also works in other languages whose syntax is inspired by C: C++, Objective-C, java, javascript, C\# to name a few. [Share](https://stackoverflow.com/a/66600158 "Short permalink to this answer") Share a link to this answer Copy link [CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/ "The current license for this post: CC BY-SA 4.0") [Improve this answer](https://stackoverflow.com/posts/66600158/edit) Follow Follow this answer to receive notifications [edited Mar 12, 2021 at 17:19](https://stackoverflow.com/posts/66600158/revisions "show all edits to this post") community wiki [2 revs](https://stackoverflow.com/posts/66600158/revisions "show revision history for this post") [chqrlie](https://stackoverflow.com/users/4593267) ## Comments Add a comment This answer is useful 5 Save this answer. Show activity on this post. Here `--` is the unary post decrement operator. ``` Copy ``` - In the beginning, the condition will evaluate as `(x > 0) // 10 > 0` - Now because the condition is true, it will go into the loop with a decremented value `x-- // x = 9` - That's why the first printed value is 9 - And so on. In the last loop `x=1`, so the condition is true. As per the unary operator, the value changed to `x = 0` at the time of print. - Now, `x = 0`, which evaluates the condition `(x > 0 )` as false and the *while* loop exits. [Share](https://stackoverflow.com/a/62755067 "Short permalink to this answer") Share a link to this answer Copy link [CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/ "The current license for this post: CC BY-SA 4.0") [Improve this answer](https://stackoverflow.com/posts/62755067/edit) Follow Follow this answer to receive notifications [edited Oct 28, 2020 at 22:50](https://stackoverflow.com/posts/62755067/revisions "show all edits to this post") community wiki [2 revs, 2 users 74%](https://stackoverflow.com/posts/62755067/revisions "show revision history for this post") [Neeraj Bansal](https://stackoverflow.com/users/8795509) ## 1 Comment Add a comment [![](https://www.gravatar.com/avatar/e7140b12949e4652885f6bb02b435f42?s=48&d=identicon&r=PG)](https://stackoverflow.com/users/225757/roland-illig) Roland Illig [Roland Illig](https://stackoverflow.com/users/225757/roland-illig) [Over a year ago](https://stackoverflow.com/questions/1642028/what-is-the-operator-in-c-c#comment128934699_62755067) You forgot to describe the `--` at the end of the loop. 2022-07-16T01:17:17.343Z+00:00 0 Reply - Copy link This answer is useful 5 Save this answer. Show activity on this post. This `-->` is not an operator at all. We have an operator like `->`, but not like `-->`. It is just a wrong interpretation of `while(x-- >0)` which simply means x has the post decrement operator and this loop will run till it is greater than *zero*. Another simple way of writing this code would be `while(x--)`. The *while* loop will stop whenever it gets a false condition and here there is only one case, i.e., `0`. So it will stop when the x value is decremented to *zero*. [Share](https://stackoverflow.com/a/62394449 "Short permalink to this answer") Share a link to this answer Copy link [CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/ "The current license for this post: CC BY-SA 4.0") [Improve this answer](https://stackoverflow.com/posts/62394449/edit) Follow Follow this answer to receive notifications [edited Oct 28, 2020 at 22:53](https://stackoverflow.com/posts/62394449/revisions "show all edits to this post") community wiki [2 revs, 2 users 60%](https://stackoverflow.com/posts/62394449/revisions "show revision history for this post") [Peter Mortensen](https://stackoverflow.com/users/63550) ## Comments Add a comment This answer is useful 0 Save this answer. Show activity on this post. That's what you mean. ``` Copywhile((x--) > 0) ``` We heard in childhood, > Stop don't, Let Go (روکو مت، جانے دو) Where a Comma makes confusion > Stop, don't let go. (روکو، مت جانے دو) Same Happens in Programming now, a SPACE makes confusion. :D [Share](https://stackoverflow.com/a/67799533 "Short permalink to this answer") Share a link to this answer Copy link [CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/ "The current license for this post: CC BY-SA 4.0") [Improve this answer](https://stackoverflow.com/posts/67799533/edit) Follow Follow this answer to receive notifications answered [Jun 2, 2021 at 5:47](https://stackoverflow.com/posts/67799533/revisions "show all edits to this post") community wiki [Numan Gillani](https://stackoverflow.com/posts/67799533/revisions "show revision history for this post") ## 3 Comments Add a comment [![](https://i.sstatic.net/EEyLy.jpg?s=64)](https://stackoverflow.com/users/4593267/chqrlie) chqrlie [chqrlie](https://stackoverflow.com/users/4593267/chqrlie) [Over a year ago](https://stackoverflow.com/questions/1642028/what-is-the-operator-in-c-c#comment119841624_67799533) This idea can be abused for distant targets in a bow and arrow style: `while((x --)> 0)` 2021-06-02T08:16:28.233Z+00:00 2 Reply - Copy link [![](https://i.sstatic.net/yVhlW.jpg?s=64)](https://stackoverflow.com/users/7469973/numan-gillani) Numan Gillani [Numan Gillani](https://stackoverflow.com/users/7469973/numan-gillani) [Over a year ago](https://stackoverflow.com/questions/1642028/what-is-the-operator-in-c-c#comment119841760_67799533) That's upto the understanding, whatever seems easy & understandable to a person, it's fine for him/her. Main Goal is to clear the concept and be a successful developer :) 2021-06-02T08:21:24.953Z+00:00 0 Reply - Copy link [![](https://i.sstatic.net/EEyLy.jpg?s=64)](https://stackoverflow.com/users/4593267/chqrlie) chqrlie [chqrlie](https://stackoverflow.com/users/4593267/chqrlie) [Over a year ago](https://stackoverflow.com/questions/1642028/what-is-the-operator-in-c-c#comment119841919_67799533) Of course. And IMHO `while (x --> 0)` is clear and effective. `x` takes all values below the starting one down to and including `0`, which is perfect for a loop enumerating index values for an array for both signed and unsigned types of `x`. 2021-06-02T08:28:29.217Z+00:00 0 Reply - Copy link Add a comment **[Protected question](https://stackoverflow.com/help/privileges/protect-questions)**. To answer this question, you need to have at least 10 reputation on this site (not counting the [association bonus](https://meta.stackexchange.com/questions/141648/what-is-the-association-bonus-and-how-does-it-work)). The reputation requirement helps protect this question from spam and non-answer activity. Start asking to get answers Find the answer to your question by asking. [Ask question](https://stackoverflow.com/questions/ask) Explore related questions - [c++](https://stackoverflow.com/questions/tagged/c%2B%2B "show questions tagged 'c++'") - [c](https://stackoverflow.com/questions/tagged/c "show questions tagged 'c'") - [operators](https://stackoverflow.com/questions/tagged/operators "show questions tagged 'operators'") - [code-formatting](https://stackoverflow.com/questions/tagged/code-formatting "show questions tagged 'code-formatting'") - [standards-compliance](https://stackoverflow.com/questions/tagged/standards-compliance "show questions tagged 'standards-compliance'") See similar questions with these tags. - The Overflow Blog - [Prevent agentic identity theft](https://stackoverflow.blog/2026/03/27/prevent-agentic-identity-theft/?cb=1) - [Building shared coding guidelines for AI (and people too)](https://stackoverflow.blog/2026/03/26/coding-guidelines-for-ai-agents-and-people-too/?cb=1) - Featured on Meta - [I’m Jody, the Chief Product and Technology Officer at Stack Overflow. Let’s...](https://meta.stackoverflow.com/questions/438369/i-m-jody-the-chief-product-and-technology-officer-at-stack-overflow-let-s-talk?cb=1 "I’m Jody, the Chief Product and Technology Officer at Stack Overflow. Let’s talk about the site redesign") - [Release notes and bug fixes for beta.stackoverflow.com](https://meta.stackoverflow.com/questions/438499/release-notes-and-bug-fixes-for-beta-stackoverflow-com?cb=1) - [Policy: Generative AI (e.g., ChatGPT) is banned](https://meta.stackoverflow.com/questions/421831/policy-generative-ai-e-g-chatgpt-is-banned?cb=1) [Visit chat](https://chat.stackoverflow.com/) Community activity Last 1 hr - Users online activity 9482 users online - 8 questions - 23 answers - 28 comments - 158 upvotes Popular tags [java](https://stackoverflow.com/questions/tagged/java)[android](https://stackoverflow.com/questions/tagged/android)[python](https://stackoverflow.com/questions/tagged/python)[visual-studio-code](https://stackoverflow.com/questions/tagged/visual-studio-code)[themes](https://stackoverflow.com/questions/tagged/themes)[c\#](https://stackoverflow.com/questions/tagged/c) Popular unanswered question [SVG & PDF render performance](https://stackoverflow.com/questions/78337184) [ios](https://stackoverflow.com/questions/tagged/ios)[swift](https://stackoverflow.com/questions/tagged/swift)[pdf](https://stackoverflow.com/questions/tagged/pdf)[svg](https://stackoverflow.com/questions/tagged/svg)[uiimage](https://stackoverflow.com/questions/tagged/uiimage) [![User avatar](https://www.gravatar.com/avatar/12b8da992014ae806a3563a3209f8c08?s=256&d=identicon&r=PG&f=y&so-version=2)](https://stackoverflow.com/users/3481904) [ernewston](https://stackoverflow.com/users/3481904) - 1k 710 days ago #### Linked [34](https://stackoverflow.com/questions/29429605/what-does-mean-in-java?lq=1 "Question score (upvotes - downvotes)") [What does --\> mean in Java?](https://stackoverflow.com/questions/29429605/what-does-mean-in-java?noredirect=1&lq=1) [38](https://stackoverflow.com/questions/25722718/what-is-in-java?lq=1 "Question score (upvotes - downvotes)") [What is \<-- in Java?](https://stackoverflow.com/questions/25722718/what-is-in-java?noredirect=1&lq=1) [15](https://stackoverflow.com/questions/39163582/how-does-the-minus-minus-less-than-operator-work-in-javascript?lq=1 "Question score (upvotes - downvotes)") [How does the minus minus less than "--\>" operator work in JavaScript?](https://stackoverflow.com/questions/39163582/how-does-the-minus-minus-less-than-operator-work-in-javascript?noredirect=1&lq=1) [7](https://stackoverflow.com/questions/39150922/java-expressions?lq=1 "Question score (upvotes - downvotes)") [Java expressions](https://stackoverflow.com/questions/39150922/java-expressions?noredirect=1&lq=1) [4](https://stackoverflow.com/questions/23861640/what-does-actually-do?lq=1 "Question score (upvotes - downvotes)") [What does --\>\> actually do?](https://stackoverflow.com/questions/23861640/what-does-actually-do?noredirect=1&lq=1) [4](https://stackoverflow.com/questions/39777302/meaning-of-operator-not?lq=1 "Question score (upvotes - downvotes)") [Meaning of "+ +" operator (not ++)](https://stackoverflow.com/questions/39777302/meaning-of-operator-not?noredirect=1&lq=1) [\-8](https://stackoverflow.com/questions/22918048/why-isnt-there-a-operator?lq=1 "Question score (upvotes - downvotes)") [Why isn't there a "\<--" operator?](https://stackoverflow.com/questions/22918048/why-isnt-there-a-operator?noredirect=1&lq=1) [5](https://stackoverflow.com/questions/35386593/what-is-symbol-in-java?lq=1 "Question score (upvotes - downvotes)") [What is --\> symbol in Java?](https://stackoverflow.com/questions/35386593/what-is-symbol-in-java?noredirect=1&lq=1) [2](https://stackoverflow.com/questions/22955361/what-does-mean-in-c?lq=1 "Question score (upvotes - downvotes)") [What does "--\>" mean in C?](https://stackoverflow.com/questions/22955361/what-does-mean-in-c?noredirect=1&lq=1) [\-4](https://stackoverflow.com/questions/41849004/what-is-the-difference-between-these-two-for-loops-in-c?lq=1 "Question score (upvotes - downvotes)") [What is the difference between these two for loops in C?](https://stackoverflow.com/questions/41849004/what-is-the-difference-between-these-two-for-loops-in-c?noredirect=1&lq=1) [See more linked questions](https://stackoverflow.com/questions/linked/1642028?lq=1) #### Related [50](https://stackoverflow.com/questions/1580757/what-is-the-official-name-of-cs-arrow-operator?rq=3 "Question score (upvotes - downvotes)") [What is the official name of C++'s arrow (-\>) operator?](https://stackoverflow.com/questions/1580757/what-is-the-official-name-of-cs-arrow-operator?rq=3) [23](https://stackoverflow.com/questions/1779685/what-is-operator-in-c?rq=3 "Question score (upvotes - downvotes)") [What is -\>\* operator in C++?](https://stackoverflow.com/questions/1779685/what-is-operator-in-c?rq=3) [12](https://stackoverflow.com/questions/5529443/what-is-operation-in-c?rq=3 "Question score (upvotes - downvotes)") [What is \>\>\> operation in C++](https://stackoverflow.com/questions/5529443/what-is-operation-in-c?rq=3) [3](https://stackoverflow.com/questions/7682072/what-exactly-is-the-operator?rq=3 "Question score (upvotes - downvotes)") [What exactly is the -\>\* operator?](https://stackoverflow.com/questions/7682072/what-exactly-is-the-operator?rq=3) [4](https://stackoverflow.com/questions/9245844/what-does-the-operator-mean-in-c?rq=3 "Question score (upvotes - downvotes)") [What does the "-\>" operator mean in C++?](https://stackoverflow.com/questions/9245844/what-does-the-operator-mean-in-c?rq=3) [20](https://stackoverflow.com/questions/18251340/what-does-this-mean?rq=3 "Question score (upvotes - downvotes)") [What does this mean "-\>"?](https://stackoverflow.com/questions/18251340/what-does-this-mean?rq=3) [3](https://stackoverflow.com/questions/19687796/c-when-do-i-use-or?rq=3 "Question score (upvotes - downvotes)") [C++ When do I use -\> or ::](https://stackoverflow.com/questions/19687796/c-when-do-i-use-or?rq=3) [1](https://stackoverflow.com/questions/33292208/what-does-operator-do-in-c?rq=3 "Question score (upvotes - downvotes)") [What does operator \<- do in c++?](https://stackoverflow.com/questions/33292208/what-does-operator-do-in-c?rq=3) [1](https://stackoverflow.com/questions/36206315/whats-the-official-name-of-and-operators-in-c-and-c?rq=3 "Question score (upvotes - downvotes)") [What's the official name of '.' and '-\>' operators in C and C++?](https://stackoverflow.com/questions/36206315/whats-the-official-name-of-and-operators-in-c-and-c?rq=3) [1](https://stackoverflow.com/questions/64915774/working-of-the-operators-followed-by-in-the-below-example?rq=3 "Question score (upvotes - downvotes)") [Working of the operators ++ followed by -\> in the below example](https://stackoverflow.com/questions/64915774/working-of-the-operators-followed-by-in-the-below-example?rq=3) #### [Hot Network Questions](https://stackexchange.com/questions?tab=hot) - [To what extent did the evacuation of Soviet factories to the Urals apply to those in the Moscow region?](https://history.stackexchange.com/questions/79944/to-what-extent-did-the-evacuation-of-soviet-factories-to-the-urals-apply-to-thos) - [Is the math word for pole in French a bad translation?](https://hsm.stackexchange.com/questions/19313/is-the-math-word-for-pole-in-french-a-bad-translation) - [Why does the hook in \\chapter fail?](https://tex.stackexchange.com/questions/761277/why-does-the-hook-in-chapter-fail) - [Is it true that Iranian Scholars are excluded from participation in the ICM 2026 in Philadelphia?](https://mathoverflow.net/questions/509496/is-it-true-that-iranian-scholars-are-excluded-from-participation-in-the-icm-2026) - [The origin of the potential in crystal](https://physics.stackexchange.com/questions/870578/the-origin-of-the-potential-in-crystal) - [Sort chef's ingredients, grouped by supplier](https://codereview.stackexchange.com/questions/301686/sort-chefs-ingredients-grouped-by-supplier) - [Parallels in sequences?](https://music.stackexchange.com/questions/143417/parallels-in-sequences) - [Did Eudoxus travel to Egypt?](https://hsm.stackexchange.com/questions/19312/did-eudoxus-travel-to-egypt) - [Where did Charles Lamb call Spenser "the poet's poet"?](https://literature.stackexchange.com/questions/31829/where-did-charles-lamb-call-spenser-the-poets-poet) - [Orientation local system of a vector bundle](https://mathoverflow.net/questions/509523/orientation-local-system-of-a-vector-bundle) - [How should an undermount sink sandwiched with plywood be removed?](https://diy.stackexchange.com/questions/329728/how-should-an-undermount-sink-sandwiched-with-plywood-be-removed) - [Total energy production of a neutrino powered generator](https://worldbuilding.stackexchange.com/questions/272998/total-energy-production-of-a-neutrino-powered-generator) - [What is the physics behind how welding works?](https://physics.stackexchange.com/questions/870560/what-is-the-physics-behind-how-welding-works) - [Compare & Contrast Genesis 9:22's idiom phrase "saw the nakedness of his father" with Ezekiel 22:10's phrase "have uncovered their fathers’ nakedness"](https://hermeneutics.stackexchange.com/questions/115530/compare-contrast-genesis-922s-idiom-phrase-saw-the-nakedness-of-his-father) - [Poor shifting after new chain](https://bicycles.stackexchange.com/questions/100108/poor-shifting-after-new-chain) - [Integration result without using Rubi](https://mathematica.stackexchange.com/questions/319080/integration-result-without-using-rubi) - [Corrupt terminal output when piping or redirecting a sudo Bash script that calls ssh?](https://unix.stackexchange.com/questions/805160/corrupt-terminal-output-when-piping-or-redirecting-a-sudo-bash-script-that-calls) - [Could we spot an alien ship entering the Solar System?](https://worldbuilding.stackexchange.com/questions/273008/could-we-spot-an-alien-ship-entering-the-solar-system) - [Elegant identity using Stirling numbers of both kinds and Bernoulli numbers](https://mathoverflow.net/questions/509522/elegant-identity-using-stirling-numbers-of-both-kinds-and-bernoulli-numbers) - [Getting accurate estimates of TSA line lengths?](https://travel.stackexchange.com/questions/203508/getting-accurate-estimates-of-tsa-line-lengths) - [tikz, drawing edge with option "double"](https://tex.stackexchange.com/questions/761275/tikz-drawing-edge-with-option-double) - [How can I restore the VS Code color theme after update 1.113?](https://stackoverflow.com/questions/79914612/how-can-i-restore-the-vs-code-color-theme-after-update-1-113) - [Is isolation needed in purely battery-powered circuits?](https://electronics.stackexchange.com/questions/767348/is-isolation-needed-in-purely-battery-powered-circuits) - [Got called back for a job, but haven't received the follow-up call](https://workplace.stackexchange.com/questions/203310/got-called-back-for-a-job-but-havent-received-the-follow-up-call) [Question feed](https://stackoverflow.com/feeds/question/1642028 "Feed of this question and its answers") # Subscribe to RSS Question feed To subscribe to this RSS feed, copy and paste this URL into your RSS reader. ![](https://stackoverflow.com/posts/1642028/ivc/d4fc?prg=8b6e37bf-4e62-4de5-8242-d00bcb1da816) default # Why are you flagging this comment? Probable spam. This comment promotes a product, service or website while [failing to disclose the author's affiliation](https://stackoverflow.com/help/promotion). Unfriendly or contains harassment/bigotry/abuse. This comment is unkind, insulting or attacks another person or group. Learn more in our [Abusive behavior policy](https://stackoverflow.com/conduct/abusive-behavior). Not needed. This comment is not relevant to the post. ``` ``` Enter at least 6 characters Something else. A problem not listed above. Try to be as specific as possible. ``` ``` Enter at least 6 characters Flag comment Cancel You have 0 flags left today # ![Illustration of upvote icon after it is clicked](https://stackoverflow.com/Content/Img/modal/img-upvote.png?v=fce73bd9724d) # Hang on, you can't upvote just yet. You'll need to complete a few actions and gain 15 reputation points before being able to upvote. **Upvoting** indicates when questions and answers are useful. [What's reputation and how do I get it?](https://stackoverflow.com/help/whats-reputation) Instead, you can save this post to reference later. Save this post for later Not now ##### [Stack Overflow](https://stackoverflow.com/) - [Questions](https://stackoverflow.com/questions) - [Help](https://stackoverflow.com/help) - [Chat](https://chat.stackoverflow.com/?tab=explore) ##### [Business](https://stackoverflow.co/) - [Stack Internal](https://stackoverflow.co/internal/?utm_medium=referral&utm_source=stackoverflow-community&utm_campaign=footer&utm_content=teams) - [Stack Data Licensing](https://stackoverflow.co/data-licensing/?utm_medium=referral&utm_source=stackoverflow-community&utm_campaign=footer&utm_content=data-licensing) - [Stack Ads](https://stackoverflow.co/advertising/?utm_medium=referral&utm_source=stackoverflow-community&utm_campaign=footer&utm_content=advertising) ##### [Company](https://stackoverflow.co/) - [About](https://stackoverflow.co/) - [Press](https://stackoverflow.co/company/press/) - [Work Here](https://stackoverflow.co/company/work-here/) - [Legal](https://stackoverflow.com/legal) - [Privacy Policy](https://stackoverflow.com/legal/privacy-policy) - [Terms of Service](https://stackoverflow.com/legal/terms-of-service/public) - [Contact Us](https://stackoverflow.com/contact) - Cookie Settings - [Cookie Policy](https://policies.stackoverflow.co/stack-overflow/cookie-policy) ##### [Stack Exchange Network](https://stackexchange.com/) - [Technology](https://stackexchange.com/sites#technology) - [Culture & recreation](https://stackexchange.com/sites#culturerecreation) - [Life & arts](https://stackexchange.com/sites#lifearts) - [Science](https://stackexchange.com/sites#science) - [Professional](https://stackexchange.com/sites#professional) - [Business](https://stackexchange.com/sites#business) - [API](https://api.stackexchange.com/) - [Data](https://data.stackexchange.com/) - [Blog](https://stackoverflow.blog/?blb=1) - [Facebook](https://www.facebook.com/officialstackoverflow/) - [Twitter](https://twitter.com/stackoverflow) - [LinkedIn](https://linkedin.com/company/stack-overflow) - [Instagram](https://www.instagram.com/thestackoverflow) Site design / logo © 2026 Stack Exchange Inc; user contributions licensed under [CC BY-SA](https://stackoverflow.com/help/licensing) . rev 2026.3.26.41518
Readable Markdown
`-->` is not an operator, it is the juxtaposition of `--` (post-decrement) and `>` (greater than comparison). The loop will look more familiar as: ``` #include <stdio.h> int main() { int x = 10; while (x-- > 0) { // x goes to 0 printf("%d ", x); } } ``` This loop is a classic idiom to enumerate values between `10` (the excluded upper bound) and `0` the included lower bound, useful to iterate over the elements of an array from the last to the first. The initial value `10` is the total number of iterations (for example the length of the array), and one plus the first value used inside the loop. The `0` is the last value of `x` inside the loop, hence the comment *x goes to 0*. Note that the value of `x` after the loop completes is `-1`. Note also that this loop will operate the **same** way if `x` has an **unsigned type** such as `size_t`, which is a strong advantage over the naive alternative `for (i = length-1; i >= 0; i--)`. For this reason, I am actually a fan of this surprising syntax: `while (x --> 0)`. I find this idiom eye-catching and elegant, just like `for (;;)` vs: `while (1)` (which looks confusingly similar to `while (l)`). It also works in other languages whose syntax is inspired by C: C++, Objective-C, java, javascript, C\# to name a few.
ML Classification
ML Categories
/Computers_and_Electronics
98.6%
/Computers_and_Electronics/Programming
96.3%
/Computers_and_Electronics/Programming/C_and_C++
94.1%
Raw JSON
{
    "/Computers_and_Electronics": 986,
    "/Computers_and_Electronics/Programming": 963,
    "/Computers_and_Electronics/Programming/C_and_C++": 941
}
ML Page Types
/Article
68.8%
/Article/FAQ
41.8%
Raw JSON
{
    "/Article": 688,
    "/Article/FAQ": 418
}
ML Intent Types
Informational
99.9%
Raw JSON
{
    "Informational": 999
}
Content Metadata
Languageen
Authornull
Publish Time2009-10-29 06:57:45 (16 years ago)
Original Publish Time2009-10-29 06:57:45 (16 years ago)
RepublishedNo
Word Count (Total)8,096
Word Count (Content)248
Links
External Links68
Internal Links365
Technical SEO
Meta NofollowNo
Meta NoarchiveNo
JS RenderedYes
Redirect Targetnull
Performance
Download Time (ms)325
TTFB (ms)314
Download Size (bytes)119,382
Shard169 (laksa)
Root Hash714406497480128969
Unparsed URLcom,stackoverflow!/questions/1642028/what-is-the-operator-in-c-c s443