C출력 결과보통 · 20점#구조체#포인터#배열

27. 구조체 배열과 화살표 연산자

다음 C 프로그램의 실행 결과를 쓰시오.

1#include <stdio.h>
2
3struct Item {
4 char name[8];
5 int price;
6 int qty;
7};
8
9int main() {
10 struct Item list[3] = {
11 {"pen", 500, 4},
12 {"cup", 1200, 2},
13 {"bag", 3000, 1}
14 };
15 struct Item *p = list;
16 int total = 0;
17 for (int i = 0; i < 3; i++) {
18 total += (p + i)->price * (p + i)->qty;
19 }
20 p++;
21 p->qty += 3;
22 (*p).price -= 200;
23 printf("%d\n", total);
24 printf("%s %d\n", p->name, p->price * p->qty);
25 printf("%c %d\n", (p + 1)->name[0], list[1].qty);
26 return 0;
27}

해설을 먼저 보면 이후 정답 시 점수가 50%만 반영됩니다.