下面是我在表弟的例子上改的
#include <stdio.h>
#include <string.h>
struct class
{
int classId;
int count;
};
struct birth
{
int year;
int month;
int day;
};
struct student
{
int num;
char name[20];
int age;
struct birth birthday;
};
struct student getStudentInfo();
int main()
{
struct class cl1 , *cl;
cl = &cl1;
cl1.classId = 3;
cl1.count = 4;
printf("%d\n%d\n",(*cl).classId,(*cl).count);
printf("%d\n%d\n",cl->classId,cl->count);
struct student stu = getStudentInfo();
printf("==============>%d\n%s\n%d\n%d %d %d\n",stu.num,stu.name,stu.age,stu.birthday.year,stu.birthday.month,stu.birthday.day);
}
struct student getStudentInfo()
{
struct student stu;
stu.num=1001;
strcpy(stu.name ,"Jin");
stu.age=20;
stu.birthday.year=1992;
stu.birthday.month=10;
stu.birthday.day=30;
return stu;
}
输出:
jianguo@jianguo:/work/study$ sudo cc 727.c -o 727
jianguo@jianguo:/work/study$ ./727
3
4
3
4
==============>1001
Jin
20
1992 10 30
jianguo@jianguo:/work/study$