结构体: 代码:结构体数组 -- 结构体嵌套一个结构体。结构体定义方法(结构体类型和结构体类型变量),以及参数调用格式,如下代码: #include<stdio.h> int a=10; int main(){ // int a=11; // printf("%d\n",a); struct Info{ char *name; int age; char *relation; };
struct home{ long tel; struct Info family; }; // struct home home1 = {13534567890,{"brother",26,"brother"}}; // struct home home2 = {18654321098,{"sister",25,"woman"}}; // // struct home Home[2] = {home1,home2}; struct home Home [2]={ {13534567890,{"brothor",26,"brother"}}, {18654321098,{"sister",25,"sister"}} }; for (int i=0; i<2; i++) { printf("姓名:%s,年龄:%d,关系:%s,电话号码:%ld\n",Home.family.name,Home.family.age,Home.family.relation,Home.tel); } return 0; }
|