gpt4 book ai didi

c++ - 在 C++ 中使用 NULL?

转载 作者:IT老高 更新时间:2023-10-28 12:37:16 25 4
gpt4 key购买 nike

Possible Duplicate:
Do you use NULL or 0 (zero) for pointers in C++?

在 C++ 中使用 NULL 还是只使用值 0 是个好主意?

在从 C++ 调用的 C 代码中使用 NULL 是否有特殊情况?喜欢 SDL?

最佳答案

在 C++ 中,NULL 扩展为 0 或 0L。看到这个quote from Stroustrup's FAQ :

Should I use NULL or 0?

In C++, the definition of NULL is 0, so there is only an aesthetic difference. I prefer to avoid macros, so I use 0. Another problem with NULL is that people sometimes mistakenly believe that it is different from 0 and/or not an integer. In pre-standard code, NULL was/is sometimes defined to something unsuitable and therefore had/has to be avoided. That's less common these days.

If you have to name the null pointer, call it nullptr; that's what it's called in C++11. Then, "nullptr" will be a keyword.

关于c++ - 在 C++ 中使用 NULL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3577580/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com