C语言 多重指针--整型&字符&字符串 int**pp
Posted DQ_CODING
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了C语言 多重指针--整型&字符&字符串 int**pp相关的知识,希望对你有一定的参考价值。
介绍
多重指针:一个指针指向另一个指针
离值越近的指针级别越大:一级
内存布局
代码
图示:
多重指针–整型
#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 p
printf("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;
}
以上是关于C语言 多重指针--整型&字符&字符串 int**pp的主要内容,如果未能解决你的问题,请参考以下文章