c++ - Does reference variable occupy memory? -
this question has answer here:
- why reference size 4 bytes - c++ 2 answers
i have read reference variable shares same memory address original variable takes space on stack. , reference has same memory address original variable, known alias.
so, question how memory allocations done reference variables ?
8.3.2 references §4
it unspecified whether or not reference requires storage
that being said, if reference needs storage, typically needs storage pointer:
struct p { int* p; }; struct r { int& r; }; static_assert(sizeof(p) == sizeof(r), "sizeof(p) == sizeof(r)");
Comments
Post a Comment