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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T04:53:56+00:00 2026-06-17T04:53:56+00:00

Test One: #include <iostream> void function(int &parameter); int main() { int variableOne = 0;

  • 0

Test One:

    #include <iostream>
    void function(int &parameter);
    int main()
    {
        int variableOne = 0;
        int variableTwo = 6;
        function(variableOne);
        std::cout << variableOne << std::endl;
        function(variableTwo);
        std::cout << variableTwo << std::endl;
        return 0;
    }
    void function(int &parameter) // ???
    {
        parameter += 5;
    }

Test Two:

    #include <iostream>
    int main()
    {
        int variableOne = 2;
        int variableThree = 7;
        int &variableTwo = variableOne;
        std::cout << variableOne << std::endl;
        &variableTwo = variableThree; // ERROR (wrong side of operand etc...)
        std::cout << variableThree << std::endl;
        return 0;
    }

1) So why is it that &parameter can be assigned the value (of the arguments) multiple times, (test one) but &variableTwo (test two) cannot be?

2) Is this because, (test one) the memory address of parameter is assigned to variableOne and variableTwo? Or, does the value of variableOne get assigned to parameter, then variableTwo later on?

3) Perhaps, is it that a new instance of parameter is created each time the function is called?

  • 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-17T04:53:57+00:00Added an answer on June 17, 2026 at 4:53 am

    When you call function with different arguments you’re creating a new reference to the argument upon each invocation.

    &variableTwo = variableThree;
    

    Here you’re trying to assign the value of variableThree to the address of variableTwo, which is illegal (and doesn’t make sense either).

    Moreover, references cannot be reseated after being created. So, even the following is illegal.

    int &variableTwo = variableOne;
    variableTwo = variableThree;
    

    Note that the same rule applies to the function as well. If you were to try and reassign the input parameter to refer to some other integer the code wouldn’t compile.

    void function(int &parameter)
    {
        int local = 42;
    
        parameter += 5;
        parameter = local; // error!
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was trying to test one of the K&R function which uses c-'0'. To
Here's a small test program I wrote: #include <iostream> using namespace std; class A
#include <iostream> using namespace std; class dummyA { int x; public: dummyA () {
suppose I have following test/ Main.py test/one/ One.py test1.txt test/two/ Two.py test2.txt What I
As the function accepted by for_each take only one parameter (the element of the
In C++ one can use reference variables in for-each statements, e.g. for (int &e
I have three files in a folder 'test' one.php two.php print.html And i have
I need some like this: module One def test; puts 'Test One'; end end
I work with Oracle 11g. I have one table: create table test (one number(2),
How does one test a method that does some interactions with the local D-Bus

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.