Home >Backend Development >C#.Net Tutorial >Are the variables defined in the main function in C language global variables?
#The variables defined in the main function in C language are not global variables, but local variables.
The variables defined in the main function have the same life cycle as the global variables.
(Recommended tutorial: C Language Tutorial)
Note: Global variables must be defined outside the function.
The main function is the first custom function executed after the program starts.
What are local variables?
A variable defined inside a function is called a local variable (Local Variable). Its scope is limited to the inside of the function. It is invalid after leaving the function, and an error will be reported if it is used again.
What are global variables?
Variables defined outside all functions are called global variables (Global Variable). By default, their scope is the entire program, that is, all source files, including .c and .h files.
The above is the detailed content of Are the variables defined in the main function in C language global variables?. For more information, please follow other related articles on the PHP Chinese website!