intmain(){// 空指针用于给指针变量进行初始化int* p =NULL;//空指针不可以进行访问// 空指针的地址为0, 0-255之间的内存编号是系统占用的,因此不可以访问// *p = 100; 访问空指针会报错return0;}
野指针
#include<iostream>usingnamespace std;intmain(){/*野指针,指针只想非法的内存空间(没有申请的空间)*/int* p =(int*)0x1100;return0;}
const 修饰指针
#include<iostream>usingnamespace std;intmain(){/*常量指针指针指向的地址可以修改 p = &b;指针指向地址的值不可以修改 *p = 20;会报错*/int a =10, b =20;constint*p =&a;p =&b;/*指针常量指针指向的地址不可以修改 p = &b;指针指向地址的值可以修改 *p = 20;会报错*/int*const p =&a;/*const即修饰指针,又修饰常量指针指向的地址不可以修改 p = &b;指针指向地址的值不可以修改 *p = 20;会报错*/constint*const p =&a;}