C출력 결과보통 · 20점#연결 리스트#구조체#비트 연산#포인터

188. 연결 리스트 순회와 시프트·XOR 누적

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

1#include <stdio.h>
2
3struct Node {
4 int val;
5 struct Node *next;
6};
7
8int main() {
9 struct Node c = {6, NULL};
10 struct Node b = {3, &c};
11 struct Node a = {5, &b};
12 struct Node *p = &a;
13 int acc = 0;
14 while (p != NULL) {
15 acc = (acc << 1) ^ p->val;
16 p = p->next;
17 }
18 printf("%d\n", acc);
19 printf("%d\n", acc & 7);
20 return 0;
21}

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