你是想这样么?
- #include<stdio.h>
- struct teacher;//结构体声明;
- struct stu{
- char name[256];
- int score;
- int age;
- struct teacher* pt;
- };
- struct teacher{
- char name[256];
- int age;
- int salary;
- struct stu* ps;
- };
- int main(void)
- {
- struct stu xiaoming = {"小明", 99, 19, NULL};
- struct teacher mingjie = {"明杰", 30, 100, &xiaoming};
- xiaoming.pt = &mingjie;
-
- printf("姓名%s, 月薪:%d 年龄%d\n", xiaoming.pt->name, xiaoming.pt->salary, xiaoming.pt->age);
- return 0;
- }
复制代码 |