结构体小程序-简单

源程序:

#include <stdio.h>
#include <malloc.h>

struct Student //结构体
{
int sid; //学号
int age; //年龄
};

struct Student *CreateStudent()
{
struct Student *stu=(struct Student *)malloc(sizeof(struct Student));//malloc()分配空间
stu->age=22;
stu->sid=1001;
return stu;
}
void ShowStudentInfo(struct Student *stu)
{
printf("sid=%d,age=%d\n",stu->sid,stu->age);
}

int main()
{
struct Student *xiaoMing=CreateStudent();
ShowStudentInfo(xiaoMing);
return 1;
}

 

posted @ 2020-12-15 20:40  bobo哥  阅读(203)  评论(0编辑  收藏  举报