数据结构Day03
动态分配内存(malloc在#include<malloc.h> 和#include<stdlib.h>中)只能自己手动释放(free)内存
#include<stdio.h>
int f();
int main(void)
{
int i=10;
i=f();
printf("i=%d\n",i);
return 0;
}
int f()
{
int j=20;//函数调用完毕,j没有了,静态变量
return j;
}
#include<stdio.h>
#include<malloc.h>
#include<stdlib.h>
#include<string.h>
struct Student
{
int sid;
char name[200];
int age;
} ;
struct Student*CreateStudent(void);
void ShowStudent(struct Student*);
int main(void)
{
struct Student*ps;
ps=CreateStudent();
ShowStudent(ps);
return 0;
}
void ShowStudent(struct Student*pst)
{
printf("%d",pst->sid);
}
struct Student*CreateStudent(void)
{
struct Student*p =(struct Student*)malloc(sizeof(struct Student));
p->sid=99;
strcpy(p->name,"sunkuan");
p->age=12;
return p;
free(p);
}