Cpp_Primer_Practice icon indicating copy to clipboard operation
Cpp_Primer_Practice copied to clipboard

【报错】练习2.32

Open dvoprm opened this issue 5 years ago • 2 comments

合法。指针可以初始化为 0 表示为空指针。

int null=0, *p=null 无法通过编译,报错

error: cannot initialize a variable of type 'int *' with an lvalue of type 'int' int *p = null; ^ ~~~~

但是int null=0, *p=0 可以通过编译

dvoprm avatar May 14 '20 08:05 dvoprm

《c++ primer 中文版 5th》p49 把int变量直接赋给指针是错误的操作,即使int变量的值恰好等于0也不行。

amoyonglee avatar Mar 31 '22 08:03 amoyonglee

是不合法的, 答案给错了. 看这个问题 https://www.zhihu.com/question/264940525?sort=created

qianyanglm avatar Oct 06 '22 02:10 qianyanglm