跨函数使用内存案例

 1 #include<stdio.h>
 2 #include<malloc.h>
 3 struct student{
 4      int age;  
 5 };
 6 struct studnet * createStudent();//函数声明,创建学生年龄
 7 void showstudent(struct studnet *);//函数声明,输出学生年龄
 8 int main(){
 9     strunct student * ps;
10     ps = createStudent();
11     showstudent(ps);
12     return 0;
13 }
14 struct studnet * createStudent(){
15     struct studnet * p = (struct student *)malloc(sizeof(struct student));
16     p->age=19;
17     return p;
18 }
19 void showstudent(struct studnet *pst){
20     printf("%d",pst->age);
21 }

 

posted @ 2019-07-27 18:04  孙晨c  阅读(212)  评论(0编辑  收藏  举报