我前两天没更是搞了一个自动化的工具,因为我们公司卷起来了,周报要PPT形式提交,我搞了个提取execel表格数据转ppt形成表格的一个玩意,我继续维护我师傅代码,新来的老哥看不懂一个二级指针,他试了老崩溃,我试了也崩溃,发现好久没写指针真的会忘,但最主要的指针是存放地址的变量即可。
所以我重新学了下指针(花了半个小时),写下此文章防止以后我忘记
#include "stdio.h"
#include "stdlib.h"
int Create(char *Name, int Age)
{
printf("Name = %s,Age = %d\n",Name ,Age);
Name = "zhangsan";
Age = 21;
printf("Name = %s,Age = %d\n",Name ,Age);
return 1;
}
typedef struct OD_Test
{
char *Name;
int Age;
int (*Create)(char *Name, int Age);
} OD_Test;
OD_Test *HostTest = NULL;
OD_Test **HostTest2 = NULL;
int main()
{
printf("Start \n");
OD_Test *HostTest = (OD_Test *)malloc(sizeof(OD_Test));
HostTest->Name = "zhangsan";
printf("Name = %s\n",HostTest->Name);
printf("HostTestAddress = %p\n",HostTest);
printf("HostTestAddress = %x\n",HostTest);
HostTest->Create = Create;
int a = HostTest->Create("wangwu",25);
printf("a = %d\n",a);
printf("end \n");
/*
int a = 1;
int *p1 = &a;
int **p2 = &p1;
printf("%d %d\n",*p1,**p2);
printf("a Address = %p\n",&a);
printf("p1 Address = %p\n",&(*p1));
printf("p2 Address = %p\n",&(**p2));
*/
printf("Start \n");
OD_Test **HostTest2 = (OD_Test **)malloc(sizeof(OD_Test*));
*HostTest2 = HostTest;
printf("%s\n",(*HostTest2)->Name);
printf("end \n");
// free(HostTest);
return 0;
}