プログラミング+α学習ブログ

勉強したことの備忘録です。

静的記憶域期間をもつ配列オブジェクトの暗黙の初期化を確認するプログラム

#include <stdio.h>

#define MAX 14

int a[MAX];   // 静的記憶域期間(全要素が0で初期化される)

int main(void)
{
    int i;
    static int b[MAX];    // 静的記憶域期間(全要素が0で初期化される)
    int c[MAX];           // 自動記憶域期間(不定値で初期化される)
    
    printf("a ");
    for (i = 0; i < MAX; i++)
        printf("%4d", a[i]);
    putchar('\n');
    
    printf("b ");
    for (i = 0; i < MAX; i++)
        printf("%4d", b[i]);
    putchar('\n');
    
    printf("c ");
    for (i = 0; i < MAX; i++)
        printf("%4d", c[i]);
    putchar('\n');
    
    return (0);
}

実行結果

a    0   0   0   0   0   0   0   0   0   0   0   0   0   0
b    0   0   0   0   0   0   0   0   0   0   0   0   0   0
c 160641988032767  1632767160641677632767   0   0   0   0   0   0   0   0