Address of a reference

前端 未结 5 1089
北恋
北恋 2021-01-16 02:40

So I am having a discussion with a friend about reference and pointers.

What we got talking about is \"you can take an address of a pointer but you cant take an addr

5条回答
  •  迷失自我
    2021-01-16 03:06

    The unary operator & returns the address of the designated object. Reference is not an object. It is reference to object. So this statement

    cout << &xRef << &x <

    outputs in the both cases the address of the designated object that is of x. Even though the compiler can allocate memory for a reference the reference itself has no address That is you can not apply operator & that to get its address. It is the object (or a function) that is referenced to by a reference that has an address.

提交回复
热议问题