跨函数使用内存(结构体指针c)
#include<stdio.h>
#include<malloc.h>
#include<string.h>
struct student
{
int sid;
int age;
char name[10];
};
student *creatp(void);
void showit(student *);//函数的声明
void main()
{
student *p;
p=creatp();
showit(p);
}
student * creatp(void)
{
student *pst=(student*)malloc(sizeof(student));
pst->age=12;
strcpy(pst->name,"ivan");
pst->sid=1802201066;
return pst;
}
void showit(student *pst)
{
printf("%d\n%s\n%d\n",pst->age ,pst->name ,pst->sid );
}
一定程度上可以节省内存使用!程序运行时间!