When using global variables, the definition of global variables is generally placed. in the cpp file, the global variable declaration is placed in. in the H file, if the global variable definition is put in one. repeated definitions may occur in hfiles. The usage is as follows:
1. Define the variable (which can be initialized or not initialized) in the C file where the main function is located, and then declare it with extern in the H file (Note: initialization is not allowed ). For other C files that need to use this variable, it is OK to include the corresponding H file before the program.
2. Define variables in a specific C file (which can be initialized or not initialized). In the H file, use extern to declare the variables. (Note: initialization is not allowed ). For other C files that need to use this variable, it is OK to include the corresponding H file before the program.
Author: "cainiao changes"