//1,指針變量指向內存中編號爲0的空間爲空指針
//2,空指針指向的內存空間是不可以訪問的
#include<iostream>
using namespace std;
int main() {
int a = 10;
int * p = &a;
cout << p << endl;
cout << &a << endl;
cout << "指針佔" << sizeof(int *) <<"字節" << endl;
cout << "指針佔" << sizeof(p) << "字節" << endl;
//1,指針變量指向內存中編號爲0的空間爲空指針
//2,空指針指向的內存空間是不可以訪問的
int * q = NULL;
//0-255內存編號爲系統佔用,不允許用戶訪問
cout << *q << endl;
system("pause");
}
野指針:指針變量指向非法的內存空間
#include<iostream>
using namespace std;
int yezhizhen() {
//指針變量p指向內存地址編號爲0x1100的空間
int * p = (int *)0x1100;
//訪問野指針報錯
cout << *p << endl;
system("pause");
return 0;
}