跨函数使用内存

#include <stdio.h>
#include <stdlib.h>

struct Student {
    int sid;
    int age;
};

struct Student * CreatStudent(void) {
    struct Student * pst = (struct Student *)malloc(sizeof(struct Student));
    pst->sid = 100;
    pst->age = 99;
    return pst;
}

void ShowStudent(struct Student * pst) {
    printf("打印: %d, %d", (*pst).sid, (*pst).age);
}

int main(void) {

    struct Student * st;
    st = CreatStudent();
    ShowStudent(st);

    return 0;
}

 

posted on 2018-12-21 10:22  JieFangZhe  阅读(100)  评论(0编辑  收藏  举报

导航