728x90
int i = 5;
printf("%d %d %d %d", ++i, i++, ++i, i++);
.
.
.
.
.
답이 6688이라고 생각하진 않으셨나요?
????? 왜 아닐까 구신님과 고민을 한 결과.
즉, printf는 왼쪽에서 오른쪽으로 스택 구조에 쌓이고, 출력은 오른쪽에서 왼쪽으로 된다는 것...!!!
그렇다면 정답은 9775!!!!
네 컴파일러가 9795래요. ㅅㅂ.. 이거에 대한 답은 아래 링크를 통해 알았다.
https://www.quora.com/What-is-the-output-of-a-5-printf-d-d-d-a-a-a-in-c-and-how
What is the output of a=5 printf ("%d %d %d", a++, a++, ++a); in c and how?
Answer (1 of 12): See printf() uses stack. Means your last argument is treated first then 2nd last argument at second place…. first argument is treated at last. Then second thing to remember is postfix increment/decrement has higher priority than prefix.
www.quora.com
네 뭐.. 컴파일 환경마다 다르다고 하네요. 암튼 printf()가 스택구조 함수라는 걸 알아보는 시간이었다. 끗~
'C' 카테고리의 다른 글
[C언어 문법] part04 C언어의 깊은 이해 (0) | 2021.12.11 |
---|---|
[C언어 문법] 20장 도전 프로그래밍 3 (0) | 2021.12.11 |
[C언어 문법] part03 포인터와 배열의 완성 (0) | 2021.12.09 |
[열혈 C 프로그래밍] 도전! 프로그래밍2 (1) | 2021.10.21 |
[열혈 C 프로그래밍] 도전! 프로그래밍1 (0) | 2021.10.21 |