Home > Backend Development > C#.Net Tutorial > Are the variables defined in the main function in C language global variables?

Are the variables defined in the main function in C language global variables?

王林
Release: 2020-06-19 15:46:02
Original
14194 people have browsed it

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template