Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3214476
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T15:03:55+00:00 2026-05-17T15:03:55+00:00

Perhaps it doesn’t matter to the compiler once it optimizes, but in C/C++, I

  • 0

Perhaps it doesn’t matter to the compiler once it optimizes, but in C/C++, I see most people make a for loop in the form of:

for (i = 0; i < arr.length; i++)

where the incrementing is done with the post fix ++. I get the difference between the two forms. i++ returns the current value of i, but then adds 1 to i on the quiet. ++i first adds 1 to i, and returns the new value (being 1 more than i was).

I would think that i++ takes a little more work, since a previous value needs to be stored in addition to a next value: Push *(&i) to stack (or load to register); increment *(&i). Versus ++i: Increment *(&i); then use *(&i) as needed.

(I get that the “Increment *(&i)” operation may involve a register load, depending on CPU design. In which case, i++ would need either another register or a stack push.)

Anyway, at what point, and why, did i++ become more fashionable?


I’m inclined to believe azheglov: It’s a pedagogic thing, and since most of us do C/C++ on a Window or *nix system where the compilers are of high quality, nobody gets hurt.

If you’re using a low quality compiler or an interpreted environment, you may need to be sensitive to this. Certainly, if you’re doing advanced C++ or device driver or embedded work, hopefully you’re well seasoned enough for this to be not a big deal at all. (Do dogs have Buddah-nature? Who really needs to know?)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T15:03:55+00:00Added an answer on May 17, 2026 at 3:03 pm

    My theory (why i++ is more fashionable) is that when people learn C (or C++) they eventually learn to code iterations like this:

    while( *p++ ) {
        ...
    }
    

    Note that the post-fix form is important here (using the infix form would create a one-off type of bug).

    When the time comes to write a for loop where ++i or i++ doesn’t really matter, it may feel more natural to use the postfix form.

    ADDED: What I wrote above applies to primitive types, really. When coding something with primitive types, you tend to do things quickly and do what comes naturally. That’s the important caveat that I need to attach to my theory.

    If ++ is an overloaded operator on a C++ class (the possibility Rich K. suggested in the comments) then of course you need to code loops involving such classes with extreme care as opposed to doing simple things that come naturally.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sorry I know this is basic, but perhaps it doesn't exist or I'm not
Perhaps what I'm trying to explain here doesn't make any sense, so I'd like
This is perhaps a very simple question but the help file doesn't seem to
Perhaps I am not getting SQL Parameters correctly, but this doesn't work for me.
I know that NSDate does not represent a timezone, but perhaps someone can advise
Perhaps this is an effect of installing the new 4.5 beta, but my simulator
Perhaps I'm a bit confused about when to use the waitForPageToLoad command, but what
Perhaps I'm not using the right terminology, but I'm struggling to try to find
Perhaps I'm at a misunderstanding in architecture - but if a machine has, say,
http://home.earthlink.net/~benfranq/Sudoku.html Perhaps somebody can tell me why it doesn't work in Internet Explorer In

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.