原完整教程链接:6.7a Null pointers
1.
// A null value is a special value that means the pointer is not pointing
// at anything. A pointer holding a null value is called a null pointer.
int *ptr(0); // ptr is now a null pointer
int *ptr2; // ptr2 is uninitialized
ptr2 = 0; // ptr2 is now a null pointer
2.
// Best practice: With C++11, use nullptr to initialize your pointers to
// a null value:
int *ptr = nullptr;
/*
C++ will implicitly convert nullptr to any pointer type. So in the
above example, nullptr is implicitly converted to an integer pointer,
and then the value of nullptr (0) assigned to ptr.
*/
网友评论