为什么在C / C ++中将地址零用作空指针?
空指针是不指向任何内容的指针。
空指针的一些用法是:
b)在尚未为该指针变量分配任何有效内存地址时初始化该指针变量。
b)当我们不想传递任何有效的内存地址时,将空指针传递给函数参数。
c)在访问任何指针变量之前检查空指针。这样,我们就可以在与指针相关的代码中执行错误处理,例如,仅当其不为NULL时才取消引用指针变量。
在C++中,如果在任何指针中分配0,则意味着该指针指向NULL。
语法
Float *p = 0 //initializing the pointer as NULL.
算法
Begin.
Declare a pointer p of the integer datatype.
Initialize *p= NULL.
Print “The value of pointer is”.
Print the value of the pointer p.
End.例:
#include <stdio.h>
int main() {
int *p= NULL;//initialize the pointer as null.
printf("The value of pointer is %u",p);
return 0;
}输出结果
The value of pointer is 0.
热门推荐
10 儿子立冬祝福语简短独特
11 对当兵的祝福语简短
12 侄儿高考试祝福语简短
13 伴郎红包祝福语朋友简短
14 媳妇生日简短祝福语朋友
15 公司年会祝福语简短最好
16 元旦感恩祝福语简短大全
17 红包祝福语简短10字
18 周六早晨祝福语简短