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

  • Home
  • SEARCH
  • 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 9106117
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T02:15:46+00:00 2026-06-17T02:15:46+00:00

In many cases, mostly when you are looping through an array and assigning values

  • 0

In many cases, mostly when you are looping through an array and assigning values to the elements, there is a scope to use post increment operator. Is it considered a good practice.

For example, in the following code where the copying is being done which one is better.

int [] to_assign;
int [] to_include;
int [] from_assign;

// Version 1
int count = 0;
while(i<<some_value>){
  if(to_include[i]==1)
     to_assign[count++] = from_assign[i];
}

// Version 2
int count = 0;
while(i<<some_value>){
  if(to_include[i]==1)
  {     
      to_assign[count] = from_assign[i];
      count++;
  }
}
  • 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-06-17T02:15:47+00:00Added an answer on June 17, 2026 at 2:15 am

    It’s purely a matter of style. Personally, I’d use whichever one makes the most logical sense. If the increment is logically part of the operation, then use the post-increment. If not, use a separate increment operation.

    Also, when you use an increment operator alone, it is generally preferred to use a pre-increment. While it won’t matter with simple types like integers, with more complex types, it can be much more efficient in languages like C++ that have operator overloading because a pre-increment doesn’t need two instances to be around at the same time. There’s no performance impact with Java, because it doesn’t have operator overloading, but if you want a consistent style rule, it should be pre-increment rather than post-increment.

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

Sidebar

Related Questions

I know there are many cases which are good cases to use multi-thread in
First of all, there are many cases where Sleep() is misused , for example
In Python scripts, there are many cases where a keyboard interrupt (Ctrl-C) fails to
I'd like to use properties for my instance variables, but in many cases, I
There are pretty many questions regarding C++ GUI toolkits for Windows, but they mostly
I know there are many documents available on net which mostly describes technical difference.
I'm using c#. In many cases I'm writing code that can benefit from a
In many prototype scripting cases, it's easier to just stick every form item (such
I have two distinct scenarios. One, where there is a many to many case,
This questions concerns mostly Unix/Linux style C++ development. I see that many C++ libraries

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.