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