プログラミング論II - s.pptVIP

  • 1
  • 0
  • 约8.78千字
  • 约 53页
  • 2016-12-29 发布于天津
  • 举报
auto変数とstatic変数の例 #include stdio.h void count(){ int x = 0; printf(x=%d\n, x); x++; } void main(){ count(); count(); count(); } x=0 x=0 x=0 実行結果 失敗作. 関数に入るたびに, 変数xは作成され, x=0と初期化される. 関数から出るたびに 変数xは消滅する. Q-* auto変数とstatic変数の例 #include stdio.h void count(){   static int x = 0; printf(x=%d\n, x); x++; } void main(){ count(); count(); count(); } 実行結果 x=0 x=1 x=2 static変数の初期化は, プログラム開始時に 1回だけ. 関数を抜けると, (見えなくなるが) 消滅せず, 値は保持される. Q-* グローバル/ローカル auto/static グローバル変数をautoにすることはできない. auto/staticを選べるのはローカル変数のみ. ローカル変数は(省略時は)自動的にauto変数になる. よって,「autoと積極的に記述すること」はほとんど無い. ローカル変数をstatic化

文档评论(0)

1亿VIP精品文档

相关文档