Summary of internal variables, static internal variables, static external variables, and external variables

Source: Internet
Author: User

Summary of internal variables, static internal variables, static external variables, and external variables:

 

Variables have two attributes: scope and lifecycle.

 

An internal variable is a variable defined in a function (or statement block,It is stored on the stack,The bucket is allocated only when the function is run.The function scope is in this function (or statement block). The lifecycle ends from the definition of this variable to the end of this function (or statement block.

 

Static internal variables, static variables defined in the function,Not Stored on stacks,Allocate storage space during compilation. The function is used in this function,But the lifecycle is fromProgramExecution starts until the program ends.,Each time you enter this function, the value of the static variable is the previous value.

 

Static external variables are defined as static variables outside all statement blocks,Not Stored on stacks,Allocate storage space during compilation. Static external variables are used to restrict the variable to be valid only in this file. If a variable with the same name is defined in other files, the compiler treats it as another variable.

 

External variables are defined outside all statement blocks,Not Stored on stacks,Allocate storage space during compilation. The function scope is from the definition to the end of this file. If the previous function needs to use this variable, you needExtern xxxThis variable can be used only when it is declared. The external variable range can be extended to other files, that is, other files can also use this variable, but before using this variable, you mustExtern
XxxDeclare the variable to use it.

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.