美文网首页
6.7a Null pointers

6.7a Null pointers

作者: Closears | 来源:发表于2017-08-26 18:00 被阅读7次

    原完整教程链接: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.
    */
    
    

    相关文章

      网友评论

          本文标题:6.7a Null pointers

          本文链接:https://www.haomeiwen.com/subject/tehvdxtx.html