What's the low-level difference between a pointer an a reference?

后端 未结 4 1979
悲哀的现实
悲哀的现实 2020-12-16 17:13

If we have this code:

int foo=100;
int& reference = foo;
int* pointer = &reference;

There\'s no actual binary difference in the ref

4条回答
  •  太阳男子
    2020-12-16 17:30

    Just to amplify, while it might be true that references are the same as pointers under the hood on nearly all compilers, it is a serious mistake to depend on that behavior. Not only is it likely to bite you on the ass when you least expect it, but it's also incorrect use of references. If it's a pointer you need, use a pointer.

提交回复
热议问题