정보처리기사 실기C언어C - 구조체 배열과 typedef난이도 2SHORT_ANSWER

정보처리기사 실기 C - 구조체 배열과 typedef 기출문제 #656

문제

다음 C 코드의 실행 결과를 쓰시오.

C
#include <stdio.h> typedef struct { char name; int value; } Node; int main() { Node list[4] = {{'X', 15}, {'Y', 25}, {'Z', 35}, {'W', 45}}; Node *current = &list[1]; int result = current[0].value + current[1].value; printf("%d", result); return 0; }

정답

60

60

해설

current는 list[1]을 가리킨다. current[0]은 current가 가리키는 위치(list[1])이므로 {Y, 25}이고, current[1]은 current에서 한 칸 뒤(list[2])이므로 {Z, 35}이다. 따라서 25 + 35 = 60이다.

이런 문제 20~50개를 한 번에 풀어보세요

매번 새로 추가되는 모의고사 + 오답 자동 복습 + 회차별 실력 추적. 회원가입 후 무료 이용.