1.二级指针
#include <iostream>
#include <windows.h>
#include <string>
using namespace std;
int main() {
int guizi2 = 888; //存有私密文件的第二个柜子;
int* guizi1 = &guizi2; //存着第二个柜子地址的第一个柜子;
int** liujian = &guizi1; //手握第一个柜子地址的liujian;
printf("他打开第一个柜子,获得第二个柜子的地址:0x%p\n",*liujian);
printf("guizi2的地址:0x%p\n",&guizi2);
int* tmp;
tmp = *liujian;
printf("访问第二个柜子的地址,拿到私密文件:%d\n",*tmp);
printf("他一步到位拿到私密文件:%d\n",**liujian); //**liujian即*(*liujian)
system("pause");
return 0;
}
#include <iostream>
#include <windows.h>
#include <string>
using namespace std;
void boy_home(int** meipo) {
static int boy = 23;
*meipo = &boy;
}
int main() {
int* meipo = NULL;
boy_home(&meipo);
printf("boy:%d\n",*meipo);
system("pause");
return 0;
}
2.多级指针
#include <iostream>
#include <windows.h>
#include <string>
using namespace std;
int main() {
int guizi1 = 888;
int* guizi2 = &guizi1;
int** guizi3 = &guizi2;
int*** guizi4 = &guizi3;
int**** guizi5 = &guizi4;
printf("柜子2拿东西:%d\n",*guizi2);
printf("柜子3拿东西:%d\n", **guizi3);
printf("柜子4拿东西:%d\n", ***guizi4);
printf("柜子5拿东西:%d\n", ****guizi5);
system("pause");
return 0;
}