Some questions about global variables in C language

1. If the global variable of C language is not initialized, its default value is 0. The reason is that global variables are stored in the bss segment after compilation.

2. Global variables in C language can be initialized at the same time as they are declared, but they cannot be assigned after they are declared.

Such as:

#include<stdio.h>
int a = 10;
int main(void)
{
    printf("a = %d\n",a);
}

This works fine and prints out a = 10.

But the following is not allowed, an error will be reported, because assignment cannot be done outside the function.

#include<stdio.h>
int a;
a=10;
int main(void)
{
    printf("a = %d\n",a);
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324907033&siteId=291194637