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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:39:16+00:00 2026-05-26T01:39:16+00:00

foo(int &bar) { bar = 5; } The call to this function would be

  • 0
foo(int &bar)
{
    bar = 5;
}

The call to this function would be

int foobar = 2;

foo(foobar);

Am I right in thinking that the function parameter essentially ‘gets’ the memory address of the variable, but does not then have to be dereferenced in foo, and that I would be changing the original value of foobar? Before this I was under the Impression that you would have to pass in a memory address like this:

foo(&foobar);

and then use the variable inside foo like this:

*bar = 5;

Am I right in thinking that this is wrong? I think, like a lot of beginners, the confusion came from thinking that a reference was like a pointer in that it held a memory address, but it’s never really a type is it? Just an operator.

  • 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-26T01:39:17+00:00Added an answer on May 26, 2026 at 1:39 am

    References are usually implemented with underlying pointers (although that is not mandated by the standard), but they are a totally different beast than pointers. A reference is simply a new name or alias for an existing variable. When you do

    void foo(int& bar)
    {
        bar = 5;
    }
    
    int foobar = 2;
    foo(foobar);
    

    you are invoking foo to be evaluated with the variable foobar, so essentially bar within foo becames foobar. The usual compiler impementation for this is to actually implement this code like this:

    void foo(int* bar)
    {
        *bar = 5;
    }
    
    int foobar = 2;
    foo(&foobar);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What is actually passed in call by reference to a function? void foo(int &a,int
Given a class like this: class Foo { public: Foo(int); Foo(const Foo&); Foo& operator=(int);
class Foo { int Bar; public: int& GetBar() const { return Bar; } }
class Foo { public: void someFunk( Foo &bar ); private: int a; ... };
Is this legal? int& foo = 0x00000000; I don't know if 'int' is the
void foo(void **Pointer); int main () { int *IntPtr; foo(&((void*)IntPtr)); } Why do I
Given a ParameterInfo p from this: void foo(int modopt(IsLong) n); p.GetOptionalCustomModifiers() returns a System.Runtime.CompilerServices.IsLong;
Given this class: class C { private: struct Foo { int key1, key2, value;
Say I have an object: struct Foo { int bar_; Foo(int bar) bar_(bar) {}
Is there a side effect in doing this: C code: struct foo { int

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.