Null pointer
- The pointer variable points to a space in memory numbered 0
- Purpose: Initialize pointer variables
- Note: memory to which a null pointer points is not accessible
Example 1: null pointer
#include <iostream>
using namespace std;
int main(a)
{
/ / null pointer
//1. A null pointer is used to initialize a pointer variable
int *p = NULL;
//2. Null Pointers are not accessible
// Memory numbers between 0 and 255 are occupied by the system and therefore cannot be accessed
//*p = 100; error
return 0;
}
Copy the code
Wild pointer
Pointer variables point to illegal memory space
Example 2: Wild pointer
#include <iostream>
using namespace std;
int main(a)
{
// the pointer variable p refers to the space with the memory address numbered 0x1100
int * p = (int *)0x1100;
// Access the wild pointer
cout << *p << endl; / / an error
return 0;
}
// Neither the null pointer nor the wild pointer is our requested space, so do not access it
Copy the code