문제
다음 C 코드의 실행 결과를 쓰시오.
C#include <stdio.h> void display(int x) { if (x <= 0) return; printf("%d ", x); display(x - 2); } int main() { display(5); return 0; }
정답
5 3 1
5 3 1
해설
display(5) 호출 시: 5 출력 후 display(3) 호출 → 3 출력 후 display(1) 호출 → 1 출력 후 display(-1) 호출하지만 조건문에 의해 종료. 따라서 출력 순서는 5 3 1이다.