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 1015487
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:24:29+00:00 2026-05-16T10:24:29+00:00

Possible Duplicate: Difference between i++ and ++i in a loop? Can anyone explain what’s

  • 0

Possible Duplicate:
Difference between i++ and ++i in a loop?

Can anyone explain what’s the difference between those:

for(unsigned col = 0; col < n; ++col, num_to_fill >>= 1U)
{

    for(unsigned row = num_to_fill; row < (1U << n); row += (num_to_fill * 2))
    {
        std::fill_n(&output[col][row], num_to_fill, 1);
    }
}

and

for(unsigned col = 0; col < n; col++, num_to_fill >>= 1U)
{

    for(unsigned row = num_to_fill; row < (1U << n); row += (num_to_fill * 2))
    {
        std::fill_n(&output[col][row], num_to_fill, 1);
    }
}

When col=0 , In ex.1 Output[col][row] will be output[1][row] and In ex.2 Output[col][row] will be output[0][row] . Am I right ?

Question 2 : Would using >>= 1U instead of /= 2 make any difference ?

  • 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-16T10:24:29+00:00Added an answer on May 16, 2026 at 10:24 am

    It does not make any difference to the value of col within the loop – assuming col is a primitive value. If col was a class, the prefix and postfix ‘++’ operators might be overloaded to do two different things, although I would consider it bad practice. Consider the following example:

    #include <iostream>
    
    using namespace std;
    
    int main() {
        for(int i = 0; i < 10; i++) {
            cout << i << endl;
        }
    
        cout << endl;
    
        for(int i = 0; i < 10; ++i) {
            cout << i << endl;
        }
    
    }
    

    Both of these just print out 0 to 9, despite the fact that you pre-increment in one, and post-increment in the other. The incrementation of i happens at the end of each run of the loop whether or not you use pre or post increment. I believe pre-incrementing is more efficient, since – and I may be wrong here – the compiler does not then need to use a temporary variable1., but this would only be noticeable if you are looping for a very long time (and of course ‘More computing sins are committed in the name of efficiency than for any other single reason’.)

    As for question 2:

    Question 2 : Would using >>= 1U
    instead of =/2 make any difference ?

    Unlikely. Bit shifting would be faster if the compiler did not optimise, but chances are that your compiler will optimise this into a bit shift.

    As a side note, I generally find doing unsigned variableName (that is, dropping the int) bad practice – although C++ will shove in an int anywhere one is missing, it is less readable to me.

    1.: Stephen in the comments (a different Stephen 😉 ) notes that – “Pre-increment is more efficient for standard library container iterators, but it’s no different for primitive types, since copying an integer is cheaper than copying a larger iterator (in particular std::set and std::map iterators).”

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

Sidebar

Related Questions

Possible Duplicate: Difference between declaring variables before or in loop? Consider the two codes
Possible Duplicate: Difference between i++ and ++i in a loop? Is there a performance
Possible Duplicate: Difference between declaring variables before or in loop? Is there any (or
Possible Duplicate: Difference between drawable and drawable-mdpi I can understand the role of drawable-ldpi,
Possible Duplicate: difference between jsp forward and redirect Does anyone knows the differences between
Possible Duplicate: Difference between i++ and ++i in a loop? Is there a difference
Possible Duplicate: For vs Foreach loop in C# What is the major difference between
Possible Duplicate: Difference between declaring variables before or in loop? I always wondered, is
Possible Duplicate: C# difference between == and .Equals() For comparing two variables we can
Possible Duplicate: Difference between (function(){})(); and function(){}(); I am trying to understand a few

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.