关于结构体嵌套结构体指针的运用

  • Post author:
  • Post category:其他


这是个例子  ,自己看吧!

#include <stdio.h>

#include <stdlib.h>

#include <unistd.h>

struct student

{




char * name;



char * id;



char * great;




};

struct test

{




struct student *std;

};

int main()

{




struct test * p = (struct test *)malloc(sizeof(struct test));



p->std = (struct student *)malloc(sizeof(struct student));












p->std->name = “xiap”;



p->std->id = “1”;



p->std->great = “2”;






printf(“%s-%s-%s\n”,p->std->name,p->std->id,p->std->great);






return 0;

}



版权声明:本文为sinat_22815613原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。