C language, global variables, local variables, external functions, internal functions, stasic and extern,

Source: Internet
Author: User

C language, global variables, local variables, external functions, internal functions, stasic and extern,

Local variable

Definition: variables defined within a code block

Scope: starts from the line that defines the variable until the end of the code block.

Lifecycle: the bucket is allocated from the row where the variable is defined. After the code block ends, it is recycled.

No Default Initial Value

 

Global Variables

Definition: variables defined outside the Function

Scope: starts from the line that defines the variable and ends with the end of the file (can be shared by all subsequent functions)

Life cycle: when a program is started, it will allocate storage space and the program will be destroyed only when it exits.

The default value is 0.

 

Global variables include external variables and internal variables.

External variables: Defined variables can be accessed by this file and other files. By default, all global variables are external variables.

Internal variables: Defined variables can only be accessed by this file, but cannot be accessed by other files

 

Internal function: the defined function can only be referenced in this document. Other files cannot be accessed.

Allow different files to have internal functions with the same name

 

External function: the defined function can be accessed by other files.

By default, all functions are external functions.

External functions with the same name are not allowed.

 

Static and extern

Valid for both functions and variables

Static defines and declares an internal function and defines an internal variable.

Static local variables are modified to prolong the life cycle of local variables. After the program ends, the local variables are destroyed and the scope of local variables is not changed.

Extern defines and declares an external function and declares an external variable.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.