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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:20:21+00:00 2026-05-27T18:20:21+00:00

In contrast to other programming languages, C++ supports three different kinds of parameter passing:

  • 0

In contrast to other programming languages, C++ supports three different kinds of parameter passing:

  • by value
  • by reference
  • by address

I am programming for a long time with C# and from the point of view from as a C# developer, C++ confuses me. In C# it is fairly easy. Just define what you want and return the result whereas C++ is much more sophisticated. Is there something like an guideline when to use by value, by reference, or by address?

  • 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-27T18:20:22+00:00Added an answer on May 27, 2026 at 6:20 pm

    The difference between passing by reference and passing by value is pretty important. When you pass by value, you’re really passing a copy of the value in question. No matter what happens in the function, the value in the caller will remain unchanged. So, say you’ve got a function that adds one to an int and returns an int:

    int addOne(int theNumber)
    {
        theNumber += 1;
        return theNumber;
    }
    

    Here, you’re passing by value. You’d call it like this:

    int a = 10;
    int b = addOne(a);    // b gets 11, but a remains the same
    

    If you want to pass by reference instead, the function would look like this:

    int addOne(int &theNumber)
    {
        theNumber += 1;
        return theNumber;
    }
    

    Note that the body of the function stays the same. Again, you call it like this:

    int a = 10;
    int b = addOne(a);    // b gets 11, but this time a is also changed to 11.
    

    The big difference here is that you’re passing a reference to a. It’s really a sort of implicit pointer to a, but you can think of it as passing a itself. Since you’re passing a instead of copy of the value of a, a itself will actually be changed by the function.

    The third way, passing the address, looks like this:

    int addOne(int *theNumber)
    {
        *theNumber = *theNumber + 1;
        return *theNumber;
    }
    

    This does the same thing as the reference version, but the pointer here is explicit. You use it like this:

    int a = 10;
    int b = addOne(&a);    // b gets 11, but this time a is also changed to 11.
    

    So, in this case you’re explicitly passing the address of a, which is to say a pointer to a. If you’re used to passing by value only, this should be familiar. This is how you pass a by reference in C and some other C-like languages. It works fine, but you have to do all the pointer stuff yourself. C++ adds the concept of passing by reference to the language to make this all easier.

    A final possibility is to pass a const reference, which avoids copying the value, but prohibits changing it in the called function. If a function takes a const reference, you can read that as a promise not to change the parameter (and it’s a promise that the compiler will enforce). This is particularly useful if the value is more than a few bytes, so that it’s desirable to avoid copying the value if you can. Objects are often passed by const reference for this reason.

    So, as a guideline, pass by value or const reference when you don’t want the thing the caller is passing to change. Pass by reference when you do want it to change. And don’t pass by pointer unless you’re dealing with a C library or other code that requires it.

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

Sidebar

Related Questions

in contrast to other logs file catalina.out has different extension. I have check logging.properties
Long-term C++ programmer (that's me) exploring other languages and is wondering whether it is
SQLite3 uses dynamic typing rather than static typing, in contrast to other flavors of
adjust image brightness/contrast using c++ without using any other 3rd party library or dependancy
In contrast to most software development organizations, our little research group within a university
Could someone compare and contrast on WCF Rest services vs. ADO.NET Data Services? What
I want to compare and contrast the various source control systems out there. Any
I'm looking for independent industry reports that compare and contrast the various source control
Is there a way to change the appearance of an icon (ie. contrast /
Please if you have used NHibernate and Entity Frameworks, please contrast your experiences.

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.