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

这是个例子  ,自己看吧!


#include
#include
#include
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;
}

你可能感兴趣的:(c)