Initialization in C

6.7.8 Initialization of C99 standard has an explanation about initialization. Here is the code to help me understand it.

 

 

#include <stdio.h>

int main(int argc, const char *argv[]) 
{
    int auto_no;
    static int static_no;
    int initialized[5] = {9};
    int uninitialized[5];

    printf("automatic number: %d\n", auto_no);
    printf("static number: %d\n", static_no);

    for (int i = 0; i < 5;i ++)
        printf("%d: %d\n", i, initialized[i]);

    for (int i = 0; i < 5;i ++)
        printf("%d: %d\n", i, uninitialized[i]);

    return 0;
}
 

jing@jingguolin:~$ gcc -std=c99 code.c

jing@jingguolin:~$ ./a.out 

automatic number: 3784692

static number: 0

0: 9

1: 0

2: 0

3: 0

4: 0

0: 134513384

1: 6242496

2: 134520820

3: -1078611800

4: 134513897



你可能感兴趣的:(C++,c,gcc,C#)