#include <stdio.h>
#include <string.h>
#include <malloc.h>
struct Student {
int sid;
int age;
};
struct Student * createStudent();
void showStudent(struct Student *);
int main() {
struct Student * ps ;
ps=createStudent();
showStudent(ps);
while (true){}
}
struct Student * createStudent() {
//使用malloc函数动态创建
struct Student * p= (struct Student *)malloc(sizeof(struct Student));
p->sid = 199;
p->age = 99;
return p;
}
void showStudent(struct Student * q) {
printf("%d %d", q->sid, q->age);
}
数据结构之结构体malloc跨函数使用内存
猜你喜欢
转载自blog.csdn.net/ywl470812087/article/details/105616093
今日推荐
周排行