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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:37:15+00:00 2026-05-28T04:37:15+00:00

Usually, parameter values are copied when being passed on. Using a reference may save

  • 0

Usually, parameter values are copied when being passed on. Using a reference may save memory, especially for big structs. However, in this case:

void foo( int parameter = 7 );
void bar( const int& parameter = 7 );

in the second declaration, what exactly will it do when the default value is used? What happens when a constant value is used for a reference parameter?

void foo( const int& parameter ) { }
...
foo( 7 );

is there any difference in efficiency between a reference and a copied value when a contant value is used?

  • 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-28T04:37:15+00:00Added an answer on May 28, 2026 at 4:37 am

    1) It will do the same thing as if it wasn’t const&. You can’t modify const& parameters, so you’re OK to bind them to constants1.

    2) There might be a very tiny difference in efficiency because you’re really (probably, implementation dependent) passing a pointer to the value instead of the value, so you’ll have to dereference the pointer to get to the real value. (Then again, the compiler could see that passing an int by const reference is a waste of time so it will pass the thing by value and pretend to you that it’s by const reference. You can’t know.) This sacrifice may be worth it for larger constructs, but generally you don’t ever need to pass something like int by const reference.


    1 mcmcc pointed out that in the case of integer literals, you are really binding the the reference to a location on the stack (unlike string literals, for instance, which reside in static memory).

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

Sidebar

Related Questions

Usually Flash and Flex applications are embedded on in HTML using either a combination
Usually, when using Windows Authentication, the software (eg Internet Explorer) tries to use Windows
Usually I tend to install things via the package manager, for unixy stuff. However,
The winsock function socket expects as third parameter the protocol what usually is IPROTO_TCP
I don't use DataSets much. Usually find myself using an ORM or just a
Usually, we use like: params[:a] #to get a specific parameter's value But how to
I created a new object() in Javascript, put some values into it and passed
I usually create parameterized queries in order to avoid SQL Injection attacks. However, I
When I run an MSI (without parameters) I usually have to click my way
Usually when I'm creating indexes on tables, I generally guess what the Fill Factor

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.