Are references stored on the heap or stack?

后端 未结 4 636
被撕碎了的回忆
被撕碎了的回忆 2021-01-12 02:44

I wonder whether the reference variables such as c in this code:

int a = 5;
int & c = a;

are allocated from heap or stack.

4条回答
  •  孤城傲影
    2021-01-12 03:33

    A reference is just an alias, and it is unspecified by the C++11 Standard whether it requires actual storage or not.

    Per Paragraph 8.3.2/4 of the C++11 Standard:

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

提交回复
热议问题