Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save chomado/5734831 to your computer and use it in GitHub Desktop.
Save chomado/5734831 to your computer and use it in GitHub Desktop.
自動記憶域期間と静的記憶域期間の変数の挙動を確認するプログラム。難しいです…orz
#include <stdio.h>
// 自動記憶域期間・静的記憶域期間の変数の挙動を確認する
int fx = 0; // 静的記憶域期間 + ファイル有効範囲
void func(void) {
static int sx = 0; // 静的記憶域期間 + ブロック有効範囲
int ax = 0; // 自動記憶域期間 + ブロック有効範囲
printf("%3d%3d%3d\n", ax++, sx++, fx++);
}
int main(void) {
int i;
puts(" ax sx fx");
puts("----------");
for(i=0; i<10; i++) {
func();
}
puts("----------");
return (0);
}
/* 実行結果
ax sx fx
----------
0 0 0
0 1 1
0 2 2
0 3 3
0 4 4
0 5 5
0 6 6
0 7 7
0 8 8
0 9 9
----------
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment