/*用结构体定义一个三口之家,家里每个成员都有:姓名,年龄,身份(如父亲),打印这个三口之家的所有成员的信息*/
#include <stdio.h>
int main(){
struct Person{
char *name;
int age;
char *status;
};
struct Person f={"成龙",60,"父亲"};
struct Person m={"林凤娇",55,"母亲"};
struct Person s={"房祖名",30,"儿子"};
struct Person pers[3]={f,m,s};
for (int i=0; i<3; i++) {
struct Person *p=pers+i;
printf("name=%s,age=%d,status=%s\n",(*p).name,(*p).age,(*p).status);
}
return 0;
} |
|