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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T05:40:12+00:00 2026-06-16T05:40:12+00:00

Possible Duplicate: size of reference variable in c++ Do C++ references consume any memory?

  • 0

Possible Duplicate:
size of reference variable in c++

Do C++ references consume any memory? If not, how can they be passed as arguments to functions?

  • 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-16T05:40:13+00:00Added an answer on June 16, 2026 at 5:40 am

    Sometimes they do and sometimes they don’t. When they need to (such as when used as data members), they do.

    For an example where they don’t need to:

    int a = 1;
    int &b = a;
    

    Now, the compiler can treat b purely as an alias for a. There is never a requirement to allocate memory for b here, because references aren’t objects.

    Another case that may be of interest:

    int some_function_call(); // function returns by value
    const int &c = some_function_call();
    

    In this case c is a reference to the temporary object that is the return value of the call. The temporary’s life is extended to the scope of c, so in that sense you could say that c consumes an int-sized piece of memory. But there’s no particular reason that the compiler needs to allocate any more than that. You might see the same emitted code as if you’d written const int c = some_function_call();, which also creates an int object with identical lifetime and the same name c.

    As for passing them as parameters — it depends on the calling convention whether parameters occupy memory or not. Some parameters might get passed in registers. Then it depends on the callee code whether that register ends up getting spilled to stack somewhere during the execution of the function. But yes, when passed as parameters and the function call not inlined, reference parameters must occupy “something”, because the caller must somehow let the callee know the address of the object referred to by the reference (the “referand”).

    All the same things can be said of pointers provided that you don’t take the address of the pointer. But in the case of pointers it’s an optimization on the compiler’s own initiative. In the case of references they’re explicitly defined in the standard to be aliases, and pointers (or at any rate addresses) happen to be the obvious means to implement that in cases where the compiler can’t treat a reference purely as an entry in its compile-time name lookup table. The only essential difference is what happens in the abstract machine described by the standard — after implementation and optimization it may well amount to the same thing.

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

Sidebar

Related Questions

Possible Duplicate: Size of character ('a') in C/C++ Can someone explain why in C
Possible Duplicate: How to find the size of a variable with out using sizeof
Possible Duplicate: Get total size of folders with find & du I can use
Possible Duplicate: Auto-size dynamic text to fill fixed size container How can I get
Possible Duplicate: Can someone explain this template code that gives me the size of
Possible Duplicate: Size of a byte in memory - Java I read this in
Possible Duplicate: Should I pass a shared_ptr by reference? Passing smart pointers as arguments
Possible Duplicate: Size of struct with a single element Given any type A and
Possible Duplicate: What is the Maximum Size that an Array can hold? i want
Possible Duplicate: Use templates to get an array's size and end address Can someone

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.