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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:40:50+00:00 2026-06-03T03:40:50+00:00

On a 32-bit machine I always get the sizeof of a reference 4 bytes

  • 0

On a 32-bit machine I always get the sizeof of a reference 4 bytes even if it’s a reference to a double, so what does it really store in this 4 bytes.

EDIT :

class A{
public:
  double&  a;
};

int main(){
  cout << sizeof(A) << endl; // this will print out 4
}
  • 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-03T03:40:52+00:00Added an answer on June 3, 2026 at 3:40 am

    The standard is pretty clear on sizeof (C++11, 5.3.3/4):

    When applied to a reference or a reference type, the result is the
    size of the referenced type.

    So if you really are taking sizeof(double&), the compiler is telling you that sizeof(double) is 4.

    Update: So, what you really are doing is applying sizeof to a class type. In that case,

    When applied to a class, the result is the number of bytes in an
    object of that class […]

    So we know that the presence of the reference inside A causes it to take up 4 bytes. That’s because even though the standard does not mandate how references are to be implemented, the compiler still has to implement them somehow. This somehow might be very different depending on the context, but for a reference member of a class type the only approach that makes sense is sneaking in a double* behind your back and calling it a double& in your face.

    So if your architecture is 32-bit (in which pointers are 4 bytes long) that would explain the result.

    Just keep in mind that the concept of a reference is not tied to any specific implementation. The standard allows the compiler to implement references however it wants.

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

Sidebar

Related Questions

I am running this on a Windows 7 (64 bit) machine. I installed RoR
i'm using templated unions to both assure myself that i always get a 64-bit
On the 32-bit machine, why the size of a pointer is 32-bit? Why not
on my 32-bit machine (with an Intel T7700 duo core), I have 15 precision
I have a 64-bit i7 machine. Suppose I allocate memory for n 32-bit integers.
The solution in How to compile a 32-bit binary on a 64-bit linux machine
I'm having a binary static library libfoo.a compiled for 32 bit linux machine. I
I want to create a Windows 7 64-bit (Ultimate) virtual machine with: Visual Studio
I'm trying to complete 100 model runs on my 8-processor 64-bit Windows 7 machine.
My dev machine is 32 bit, and my target is a 64 bit web

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.