• In C and ‘old’C++ the null pointer is the preprocessor macro NULL. ( just a plain 0 )
• C++11 introduces nullptr; A keyword that unambiguously represents a pointer pointing to nowhere. ( std::nullptr_t )
• It is a strongly typed null pointer, like Java or C# null.
• No ambiguity when trying to pass a null pointer to something acceptingan int.
• It is a keyword, so you cannot define it to whatever you want.
For example:
• In‘old’C++:
• In C++ 11:
本文深入探讨了C++11中引入的nullptr关键字,对比了其在处理空指针时的优势,以及如何在不同场景下使用它,确保代码的清晰性和安全性。
286

被折叠的 条评论
为什么被折叠?



