C++ primer 第五版的练习题:
Exercise 2.25: Determine the types and values of each of the following variables.
(a) int* ip, &r = ip;
请问怎么理解 &r = ip ?
我实在理解不能。。。
r 是一个 int 的引用,如何可以用 ip (一个 int 的指针)赋值呢?
--
补充:
正如 @araraloren 在回答中指出的,
这句编译时会报错:
int* ip, &r = ip;
要改成:
int* ip, *&r = ip;
或者
int* ip, &r = *ip;
才可以编译通过。
The type of ip is int*
The type of r is int&
&r = ip; //The compiler will give an error
Maybe the idea of the question is to distinguish the type, and the correctness of the code is second?
&r is the address of r. No one asked to assign int* to r, but to &r, so *(&r)=*ip