huangmingchuan / Cpp_Primer_Answers

《C++ Primer》第五版中文版习题答案

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

练习 2.27答案存在问题

zhangnuc opened this issue · comments

(b) int *const p2 = &i2; 应该是不合法的。
我自己代码尝试了一下,会返回报错“error: cannot initialize a variable of type 'int *const' with an rvalue of type 'const int * “

我理解的原因是由于i2是一个常量,而常亮的地址只能被存放在 指向常量的指针中。p2是一个常量指针,而非 指向常量的指针。