Are links stored on the heap or stack?

I wonder if reference variables are relevant, such as cin this code:

int a = 5;
int & c = a;

allocated from a heap or stack. Can anyone help? Thanks

+5
source share
4 answers

A link is just an alias, and it is not defined by the C ++ 11 standard, whether it needs actual storage or not.

In clause 8.3.2 / 4 of the C ++ 11 standard:

It is not indicated whether reference (3.7) is required for storage.

+14
source

Links are just aliases and don't need to be highlighted anywhere. The standard does not specify this type of detail to such an extent that it is not even required that the links have any kind of storage.

+4
source

, - - .

Regarding the reformulated question, the way links are used implies that they will mainly be distributed across the stacks. This is in all non-static scenarios where their storage cannot be omitted. And this C ++ is a high-performance programming language that skips everything that is not used.

+2
source

Most compilers treat links as limited pointers.

0
source

All Articles