6.7a Null pointers

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

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容

  • 背景 一年多以前我在知乎上答了有關LeetCode的問題, 分享了一些自己做題目的經驗。 張土汪:刷leetcod...
    土汪閱讀 12,766評論 0 33
  • Android 自定義View的各種姿勢1 Activity的顯示之ViewRootImpl詳解 Activity...
    passiontim閱讀 172,814評論 25 708
  • 國家電網公司企業標準(Q/GDW)- 面向對象的用電信息數據交換協議 - 報批稿:20170802 前言: 排版 ...
    庭說閱讀 11,081評論 6 13
  • 今天吃過午飯我乘坐16路公交來到西站旁的花鳥市場,先到朋友的水族店坐了會兒!觀賞了店內的一些熱帶小魚,稍后去他朋友...
    愛運動的洋閱讀 205評論 0 1
  • 曾聽夜雨 順著屋檐 想像萬千里 曾望星辰 借著微光 數遍花落無期 踏遍路途遙遠 穿過幾雙鞋 去見自己 意識清醒 也...
    雨安陽閱讀 138評論 0 1