Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

size of reference variable in c++ [closed]

Tags:

c++

I was wondering why this question wasn't discussed in stack overflow? reference is just an other name to variable so how does execution happen at memory level

are references implemented as pointers inside?

like image 769
Ravi Avatar asked Dec 20 '12 03:12

Ravi


1 Answers

How references are implemented is purely an implementation detail. But Yes, most implementations would implement them using pointers.
sizeof operator applied on an reference gives you the size of the element it referes to.

What is the size of the reference itself?

C+11 Standard: § 8.3.2.4

It is unspecified whether or not a reference requires storage (3.7).

Note that, Unspecified means that an compiler implementation does not need to document how it implements a reference. Neither should you consider the implementation to be anything specific. In short, the language standard treats reference implementation as an detail which user of the language does not need to know and hence it abstracts this detail.

like image 112
Alok Save Avatar answered Sep 21 '22 13:09

Alok Save