[問題] c函式的問題

作者: pophitjazz (沒有暱稱)   2014-04-16 23:34:26
開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
DEV C++
預期的正確結果(Expected Output):
0
1
2
程式碼(Code):(請善用置底文網頁, 記得排版)
void countdown(int count){
if (count != 0){
countdown(count-1);
}
printf("%d\n", count);
return;
}
int main(){
countdown(2);
system("pause");
return 0;
}
想請教一下,若printf那行寫在if之前,輸出為2->1->0。為何放在return前
輸出就成為0->1->2。
作者: prismwu   2014-04-16 23:42:00
拿筆寫下每行結果 就知道了
作者: pophitjazz (沒有暱稱)   2014-04-16 23:57:00
試了一下 還是卡住...冏count=0時,才會printf出來,為何count還會等於1阿...我好像知道了....XD
作者: celestialgod (天)   2014-04-17 01:04:00
位置換一下XD
作者: longlongint (華哥爾)   2014-04-17 09:14:00
看遞迴或堆疊

Links booklink

Contact Us: admin [ a t ] ucptt.com