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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T04:04:42+00:00 2026-05-18T04:04:42+00:00

These last weeks, I found myself using a lot of const everywhere. Not only

  • 0

These last weeks, I found myself using a lot of const everywhere. Not only in methods or arguments declarations, but even for temporary variables.

Let me illustrate with a simple function.

I used to write:

// A dummy function that sums some computation results
unsigned int sum_results(const Operation& p1, const Operation& p2)
{
  unsigned int result1 = p1.computeResult();
  unsigned int result2 = p2.computeResult();

  // Well this function could be in one single line but
  // assume it does more complex operations
  return result1 + result2;
}

But now it is more like:

// A dummy function that sums some computation results
unsigned int sum_results(const Operation& p1, const Operation& p2)
{
  const unsigned int result1 = p1.computeResult();
  const unsigned int result2 = p2.computeResult();

  // Well this function could be in one single line but
  // assume it does more complex operations
  return result1 + result2;
}

The latter makes more sense to me and seems less error prone. (I admit that in this example, it doesn’t really matter) However I’ve seen very few code samples where const was used on temporary/local variables. And I’d like to understand why.

Is there any reason why this isn’t a common case ? Am I abusing with my use of const ? Or is it just me that has been looking at the wrong samples ?

  • 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-18T04:04:43+00:00Added an answer on May 18, 2026 at 4:04 am

    Using const on local variables improves code clarity, so it’s a good idea. You see const and you immediately know that the variable is never changed later in scope. It’s from the same series as making functions short and returning early.

    Developers are lazy – they often think that it’s a useless word that doesn’t change anything. IMO they are wrong.

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

Sidebar

Related Questions

I was building something using jQuery's AutoComplete plugin last week, but today I found
I noticed the last few weeks that programmers with higher experience do not discuss
I have hack I need to employ under these conditions: It's the last page
I request a website header, however, there is not Last-Modified info in this http
I've been following the javascript questions here for the last few weeks, and I've
This is a pipeline on branch frontend over the last two weeks. | Stash@{3}
I have been studding GIT for the last couple of weeks in an attempt
School is back in session and I've found myself at a loss. At the
Coming from the OOP I started in the last weeks to read about functional
I've launched an application last week and have noticed since that in Chrome only

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.