Skip to content

Instantly share code, notes, and snippets.

@hiroshiro
Created March 18, 2015 10:42
Show Gist options
  • Save hiroshiro/b35570b8999e12295a09 to your computer and use it in GitHub Desktop.
Save hiroshiro/b35570b8999e12295a09 to your computer and use it in GitHub Desktop.
再帰呼び出しテスト詳説 CポインタRichard Reeseオライリー・ジャパン
#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