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

The Archive Base Latest Questions

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

Possible Duplicate: What’s the difference between passing by reference vs. passing by value? I

  • 0

Possible Duplicate:
What’s the difference between passing by reference vs. passing by value?

I know that the title can represent many other answered questions, I believe that my very specific question wasn’t answered in other threads (I have searched, sorry if it’s a duplicate).

To business: consider the next signatures:

A:

void MyFunction(long int x);

B:

void MyFunction(long int & x);

and the next usage:

void main()
{
  short int y = 0;
  MyFunction(y);
  ...
}

My question is related to the memory consumption of the parameter in the memory stack frame of MyFunction.

  1. In case A, the parameter is passed by-value, does it mean that it will consume sizeof(short int) bytes?

  2. In case B, the parameter is passed by-reference, assuming the compiler will implement it with a pointer, does it mean it will consume sizeof(pointer_type) bytes – which is probably more than short int?
    (I was once told that when using a reference it might consume 64 bits anyway, depending on the platform)

Note that the function receives long int type as I would like to know if it has any effect in both cases.

And another tiny question – can anyone post an example in which the compiler will NOT implement by-reference passed parameter using a pointer?

Thanks,
Asaf.

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

    The answers necessarily depend on the compiler, architecture, the ABI etc.

    In what follows, I assume that the parameters in question are actually passed on the stack and not in registers (big assumption!), and there are no aggressive optimizations.

    In case A, the parameter is passed by-value, does it mean that it will consume sizeof(short int) bytes?

    No, it will consume sizeof(long int) bytes since it will be widened first to match MyFunction()‘s signature.

    In case B, the parameter is passed by-reference, assuming the compiler will implement it with a pointer, does it mean it will consume sizeof(pointer_type) bytes

    In a word, yes. You can’t pass a short& where a long& is expected, so I assume you meant that you’re passing a long& here.

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

Sidebar

Related Questions

Possible Duplicate: What's the difference between passing by reference vs. passing by value? If
Possible Duplicate: What's the difference between passing by reference vs. passing by value? I
Possible Duplicates: What's the difference between passing by reference vs. passing by value? Java
Possible Duplicate: Difference between ref and out parameters in .NET I know that ref
Possible Duplicate: Difference between Color.red and Color.RED I have seen that the Java class
Possible Duplicate: Difference between pointer variable and reference variable in C++ When should I
Possible Duplicate: Difference between pointer variable and reference variable in C++ I am reading
Possible Duplicate: Difference between “var” and “object” in C# I would like to know
Possible Duplicate: Difference between -%> and %> in rails I need to know what
Possible Duplicate: Difference between pointer variable and reference variable in C++ As I am

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.