KAIHATSUGIKEN GROUP

C PROGRAMMING LANGUAGE




********************************************************************************
17 構造体と共用体
************
構造体とは複数の変数をひとまとまりにしたもの
************
taro age 6 height 120
jiro age 4 height 100
****
main()
{
struct child
{
char name[10];
int age,height;
};
struct child x,y;
sprintf(x.name,"taro");x.age=6;x.height=120;
sprintf(y.name,"jiro");y.age=4;x.height=100;
printf("%s,%d,%d\n",x.name,x.age,x.height);
printf("%s,%d,%d\n",y.name,y.age,y.height);
}
****
taro age 6 height 120
jiro age 4 height 100
****
main()
{
struct child{char name[10];   			/* structで構造体の型枠宣言 */
int age,height;
};
struct child x,y;
sprintf(x.name,"taro");x.age=6;x.height=120;
sprintf(y.name,"jiro");y.age=4;x.height=100;
printf("%s,%d,%d\n",x.name,x.age,x.height);
printf("%s,%d,%d\n",y.name,y.age,y.height);
}
****
taro age 6 height 120
jiro age 4 height 100
****
main()
{
struct child{char name[10];  			 /* structで構造体の型枠宣言 */
int age,height;				 	            /* 型枠名はchild */
};
struct child x,y;
sprintf(x.name,"taro");x.age=6;x.height=120;
sprintf(y.name,"jiro");y.age=4;x.height=100;
printf("%s,%d,%d\n",x.name,x.age,x.height);
printf("%s,%d,%d\n",y.name,y.age,y.height);
}
****
taro age 6 height 120
jiro age 4 height 100
****
main()
{
struct child{char name[10];   			/* structで構造体の型枠宣言 */
int age,height;	        /* 構成要素を宣言 name[10]をint age,heightにしている*/
};
struct child x,y;
sprintf(x.name,"taro");x.age=6;x.height=120;
sprintf(y.name,"jiro");y.age=4;x.height=100;
printf("%s,%d,%d\n",x.name,x.age,x.height);
printf("%s,%d,%d\n",y.name,y.age,y.height);
}
****
taro age 6 height 120
jiro age 4 height 100
****
main()
{
struct child{char name[10];   			/* structで構造体の型枠宣言 */
int age,height;
};
struct child x,y;     			/* struct childで構造体の変数を宣言 */
sprintf(x.name,"taro");x.age=6;x.height=120;
sprintf(y.name,"jiro");y.age=4;x.height=100;
printf("%s,%d,%d\n",x.name,x.age,x.height);
printf("%s,%d,%d\n",y.name,y.age,y.height);
}
****
taro age 6 height 120
jiro age 4 height 100
****
main()
{
struct child{char name[10];   			/* structで構造体の型枠宣言 */
int age,height;
};
struct child x,y;			     /* 構造体の変数としてx,yにする */
sprintf(x.name,"taro");x.age=6;x.height=120;
sprintf(y.name,"jiro");y.age=4;x.height=100;
printf("%s,%d,%d\n",x.name,x.age,x.height);
printf("%s,%d,%d\n",y.name,y.age,y.height);
}
****
taro age 6 height 120
jiro age 4 height 100
****
main()
{
struct child{char name[10];   			  /* structで構造体の型枠宣言 */
int age,height;
};
struct child x,y;
sprintf(x.name,"taro");x.age=6;x.height=120;/*name[10]の先頭アドレスをx.nameに*/
sprintf(y.name,"jiro");y.age=4;x.height=100;
printf("%s,%d,%d\n",x.name,x.age,x.height);
printf("%s,%d,%d\n",y.name,y.age,y.height);
}
****
taro age 6 height 120
jiro age 4 height 100
****
main()
{
struct child{char name[10];  			  /* structで構造体の型枠宣言 */
int age,height;
};
struct child x,y;
sprintf(x.name,"taro");x.age=6;x.height=120;	       /* x.nameにtaroを代入 */
sprintf(y.name,"jiro");y.age=4;x.height=100;
printf("%s,%d,%d\n",x.name,x.age,x.height);
printf("%s,%d,%d\n",y.name,y.age,y.height);
}
****
taro age 6 height 120
jiro age 4 height 100
****
main()
{
struct child{char name[10];   			/* structで構造体の型枠宣言 */
int age,height;
};
struct child x,y;
sprintf(x.name,"taro");x.age=6;x.height=120;  /* 構造体xの要素x.age,x.height*/
sprintf(y.name,"jiro");y.age=4;x.height=100;
printf("%s,%d,%d\n",x.name,x.age,x.height);
printf("%s,%d,%d\n",y.name,y.age,y.height);
}
****
taro age 6 height 120
jiro age 4 height 100
****
main()
{
struct child{char name[10];  			 /* structで構造体の型枠宣言 */
int age,height;
};
struct child x,y;
sprintf(x.name,"taro");x.age=6;x.height=120;
sprintf(y.name,"jiro");y.age=4;x.height=100;
printf("%s,%d,%d\n",x.name,x.age,x.height);          /* 通常の変数と同じ扱い */
printf("%s,%d,%d\n",y.name,y.age,y.height);
}
****
taro age 6 height 120
jiro age 4 height 100
****
main()
{
struct child{char name[10];   			/* structで構造体の型枠宣言 */
int age,height;
};
struct child x,y;
sprintf(x.name,"taro");x.age=6;x.height=120;
sprintf(y.name,"jiro");y.age=4;x.height=100;
printf("%s,%d,%d\n",x.name,x.age,x.height);
printf("%s,%d,%d\n",y.name,y.age,y.height);	    /* 通常の変数と同じ扱い */
}