과자 상자 구조체를 만들어 보자.
“과자 상자”는 “여러 종류의 과자”가 들어있는 상자이다.
과자 이름을 잘모르니 적당히 딸기맛,초콜릿맛,바닐라맛 과자라고 할께.
과자 상자 (Cookie Box)
과자 상자 구조체를 만들면 이렇다.
#include <stdio.h>
typedef char 동그란과자;
typedef int 네모난과자;
typedef float 별모양과자;
struct 과자상자_t {
동그란과자 a;
네모난과자 b;
별모양과자 c;
};
int main() {
struct 과자상자_t 내과자상자;
struct 과자상자_t 동생과자상자;
내과자상자.a = 0x41;
내과자상자.b = 111;
내과자상자.c = 3.14;
동생과자상자.a = 0x61;
동생과자상자.b = 222;
동생과자상자.c = 2.71;
printf("%c, %d, %4.2f\\r\\n", \\
내과자상자.a, 내과자상자.b, 내과자상자.c);
printf("%c, %d, %4.2f\\r\\n", \\
동생과자상자.a, 동생과자상자.b, 동생과자상자.c);
return 0;
}
#include <stdio.h>
typedef char cir_t;
typedef int rect_t;
typedef float star_t;
typedef struct _cookie_box_t {
cir_t a;
rect_t b;
star_t c;
} cookie_box_t;
int main() {
cookie_box_t mcb; // my...cookie...
cookie_box_t bcb; // brother's...cookie...
mcb.a = 0x42;
mcb.b = 111;
mcb.c = 3.14;
bcb.a = 0x61;
bcb.b = 222;
bcb.c = 2.71;
printf("%c, %d, %4.2f\\r\\n", \\
mcb.a, mcb.b, mcb.c);
printf("%c, %d, %4.2f\\r\\n", \\
bcb.a, bcb.b, bcb.c);
return 0;
}