Static usage Summary

Source: Internet
Author: User

A static local variable

1 storage space allocation scope lifetime

Static is allocated in the static storage area, and the scope is limited to the internal function that declares the variable. InProgram

The entire running period is not released, and the lifetime runs throughout the entire process of running the program.

AutoThe type is distributed on the stack and belongs to the dynamic storage class, which occupies the dynamic storage space. The scope is limited to the function that declares the variable. The function is automatically released after the function call ends. The lifetime is within the function that declares the variable.

2Processing Method when initial values are assigned

Static static local variables assign initial values at compilation, that is, only the initial values are assigned once;

Auto auto variable assigns an initial value when the function is called. Every time the assign function is called, the initial value is re-assigned, which is equivalent to executing a value assignment statement.

3. Processing Method without initial values

If the initial value is not assigned when defining a local variable:

Static local variables. The initial value 0 (For numeric variables) or null characters (for character variables) are automatically assigned during compilation ).

Auto automatic variable. If no initial value is assigned, its value is an uncertain value.

 

2. Static external global variables

InCLanguageStaticIt is also used to declare static external global variables, so the scope of this global variable is restricted within this file.

If the function before the definition point wants to call this variable, you should use the keyword before reference.ExternMake an "external variable Declaration" for this variable ".

This variable is an external variable that has been defined. With this declaration, you can legally use this external variable from the "Declaration.

If the declared global variables do not want to be accessed and used by other files, add the keyword static before the declaration.

 

Three static external functions

The function in C language is global by default. If an external file is to be referenced, you can add an extern. If you do not want to be referenced, use static modification.

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.