C Global Variable Declaration

In C language, global variables can be defined at any position outside of functions, as shown below:

#include <stdio.h>

int globalVariable; // 定义一个全局变量

int main() {
    globalVariable = 10; // 全局变量赋值
    printf("Global variable value: %d\n", globalVariable); // 输出全局变量的值
    return 0;
}

In the example above, globalVariable is defined as a global variable, which can be accessed and assigned values at any location in the program. Generally, global variables are defined outside of functions and can be accessed by any function within the program.

bannerAds