介绍
多重指针:一个指针指向另一个指针
离值越近的指针级别越大:一级
内存布局
代码
图示:
多重指针–整型
#include<stdio.h>
#include<string.h>
//多重指针--整型//二级指针
void two()
{printf("二级指针:\n");int a=896;int *p=&a,**pp=&p;printf("a=%d self-address=%p\n",a,&a);printf("a=%d address=%p self-address=%p\n",*p,p,&p);printf("a=%d address=%p self-address=%p\n",**pp,pp,&pp);
}//三级指针
void three()
{printf("三级指针:\n");int a=57877777;int *p=&a,**pp=&p,***ppp=&pp;printf("a=%d self-address=%p\n",a,&a);printf("a=%d address=%p self-address=%p\n",*p,p,&p);printf("a=%d address=%p self-address=%p\n",**pp,pp,&pp);printf("a=%d address=%p self-address=%p\n",***ppp,ppp,&ppp);
}int main()
{two();three();getchar();return 0;
}
多重指针–字符
#include<stdio.h>
#include<string.h>
//多重指针--字符//二级指针
void two()
{printf("二级指针:\n");char a='i';char *p=&a,**pp=&p;printf("a=%c self-address=%p\n",a,&a);printf("a=%c address=%p self-address=%p\n",*p,p,&p);printf("a=%c address=%p self-address=%p\n",**pp,pp,&pp);
}//三级指针
void three()
{printf("三级指针:\n");char a='y';char *p=&a,**pp=&p,***ppp=&pp;printf("a=%c self-address=%p\n",a,&a);printf("a=%c address=%p self-address=%p\n",*p,p,&p);printf("a=%c address=%p self-address=%p\n",**pp,pp,&pp);printf("a=%c address=%p self-address=%p\n",***ppp,ppp,&ppp);
}int main()
{two();three();getchar();return 0;
}
多重指针–字符串
#include<stdio.h>
#include<string.h>
//多重指针--字符串//三级指针
void two()
{printf("三级指针:\n");char *a="hello world";char **p=&a,***pp=&p;printf("c=%c a=%s self-address=%p\n",*a,a,&a);//char **p=&a=a的地址 根本没有存储"hello world"的地址,不能使用 %s pprintf("a=%s address=%p self-address=%p\n",a,p,&p);printf("a=%s address=%p self-address=%p\n",a,pp,&pp);
}int main()
{two();getchar();return 0;
}