char *str = "Hello";
char *ptr = str;
char *&rptr = str;
char *world = "World";
//------------------------------
rptr = world;
std::cout << str << std::endl; // Output: World
char *str = "Hello";
char *ptr = str;
char *&rptr = str;
char *world = "World";
//--------------------------------
ptr = world;
std::cout << str << std::endl; // Output: Hello
str 和 rptr 名称不同,但是是相同的指针,修改 rptr,str 随之改变。引用的指针非法,指针需要指向对象,引用不是对象。
Reference to pointer