본문 바로가기

C

여러 분은 이 답이 뭐라고 생각하십니까? 알면 상위 1% 코딩 실력을 가진 사람

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()가 스택구조 함수라는 걸 알아보는 시간이었다. 끗~