Posted on 2011-05-13 11:55
xsong 阅读(199)
评论(0) 编辑 收藏 所属分类:
c
结构体
*
struct Complex{
double x,y;
} z1;
//或者
struct Complex{
double x,y;
};
struct Complex z1;
//声明时初始化
struct Stu{
char name;
}s1={'s'};
//先声明,后初始化
struct Stu{
char name;
};
struct Stu s1={s};
//结构体赋值 ,copy s1的内容给s2
struct Stu s2=s1;
s2.name='m'
printf("s1.name %c",s1.name); // print s
printf("s2.name %c",s2.name); //print m
//结构体嵌套
struct dog{
char run;
};
struct cat{
char run;
};
struct animal{
struct dog dd;
struct cat cc;
};
//嵌套的结构体分别初始化
struct dog dd={'d'};
struct cat cc={'c'};
struct animal a1={dd ,cc};
printf("dog-dd run is %c \n",a1.dd.run);
printf("cat-cc run is %c",a1.cc.run);