您的位置:首页 > 编程语言 > C语言/C++

c语言 malloc小案例1

2015-08-18 00:06 579 查看
#include<stdio.h>

#include<malloc.h>

struct  Student * CreateStudent();

ShowStudentInfo(struct Student * stu);

struct Student{

  int sid;

  int age;

};

main(void){

  struct Student * xiaoMing =  CreateStudent();

  ShowStudentInfo(xiaoMing);

}

 struct  Student * CreateStudent(){

     struct Student * stu = (struct Student *) malloc(sizeof(struct Student) );

     stu->age = 100;

     stu->sid = 01;

     return stu;

 }

 ShowStudentInfo(struct Student * stu){

    printf("sid = %d,age = %d",stu->sid,stu->age);

  }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: