Created
March 18, 2015 10:42
-
-
Save hiroshiro/b35570b8999e12295a09 to your computer and use it in GitHub Desktop.
再帰呼び出しテスト詳説 CポインタRichard Reeseオライリー・ジャパン
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int Print(); | |
int main() | |
{ | |
int p = 4; | |
printf("Value of Print: %d\n", Print(p)); | |
} | |
int Print(int n) { // 数を1からnまで後ろ向きに印刷する | |
if(n == 0) // これが終了ベースケース | |
return 0; | |
else { | |
printf("%d\n", n); | |
return Print(n-1); // 自分自身への再帰の呼び出し | |
} | |
} | |
/* 実行結果 | |
4 | |
3 | |
2 | |
1 | |
Value of Print: 0 | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment