#include <stdio.h>
#include <stdlib.h>
typedef struct std
{
char date;
struct std *p;
}std;
std* addx(void)
{
std* p=(std *)malloc(sizeof(std));
printf("addx函数中:%p\n",p);
return p;
}
void addy(std **p)
{
*p=(std *)malloc(sizeof(std));
printf("(指针本身) addy函数中*p:%p\n\n",*p);
printf("(指针地址)addy函数中的p:%p\n\n",p);
}
int main(void)
{
std *p=NULL;
//一级指针
p=addx();
printf(" 主函数中:%p\n",p);
free(p);
printf("==========\n");
//&p,传指针的地址,相当于二级指针
addy(&p);
printf("(指针本身) 主函数中p:%p\n\n",p);
printf("(指针地址) 主函数中&p:%p\n\n",&p);
free(p);
printf("==========\n");
return 0;
}
addx函数中:00000000002DFC80
主函数中:00000000002DFC80
==========
(指针本身) addy函数中*p:00000000002DFC80
(指针地址)addy函数中的p:000000000022FE48
(指针本身) 主函数中p:00000000002DFC80
(指针地址) 主函数中&p:000000000022FE48
==========
--------------------------------
Process exited after 0.007449 seconds with return value 0
请按任意键继续. . .
|