Note when declaring local variables and global variables.
/* ===================================================== ============================================================ Name: testVariable. c Author: lf Version: Copyright: Your copyright notice Description: considerations when declaring local variables and global variables. global variables can only be assigned constant values, however, local variables can be assigned values by constants, expressions, and functions. why? The program needs to use appropriate values to initialize global variables during execution. Therefore, the initial values must be stored in the executable files generated by compilation. Therefore, the initial values must be calculated during compilation. therefore, if you initialize the global variable: double pi2 = acos (-1.0); you must call the acos function when the program is running to calculate the corresponding result. here, we mainly need to differentiate the two phases during compilation and runtime. to simplify the C language of the compiler, the global variables can only be defined using constant expressions. otherwise, the error "initializer element is not a constant expression" is returned. If the global variable is defined: int minute = 480; int hour = minute/60. this is because although it is possible to calculate the hour value during compilation, minute/60 is not a constant expression and does not meet the syntax specification. ========================================================== =============================================================== */# include <stdio. h> # include <stdlib. h> # include <math. h> double pi1 = 3.14159; // the error message is as follows: // initializer element is not a constant expression // double pi2 = acos (-1.0 ); // int hour = minute/60 is incorrect, and the prompt is as follows: // initializer element is not a constant expression // int minute = 480; // int hour = minute/60; int main (void) {printf ("pi1 = % f \ n", pi1); // printf ("pi2 = % f \ n", pi2 ); double pi3 = acos (-1.0); printf ("pi3 = % f \ n", pi3); // printf ("minute = % d \ n", minute ); // printf ("hour = % d \ n", hour); return EXIT_SUCCESS ;}