Differences between static global variables and common global variables/differences between static local variables and common local variables/differences between static functions and common functions

Source: Internet
Author: User

The description of global variables (external variables) is preceded by static
It constitutes a static global variable. Global variables are static storage, and static global variables are also static storage.
The two are not different in storage methods.The difference between the two lies in that the scope of non-static global variables is the whole sourceProgramWhen a source program is composed of multiple source files, non-static global variables are valid in each source file. The static global variable limits its scope, that is, it is valid only in the source file that defines the variable,
It cannot be used in other source files of the same source program.

Because the scope of static global variables is limited to one source file, they can only be shared by functions in the source file. Therefore, errors in other source files can be avoided.

What is the difference between static global variables and common global variables? STATIC global variables are only made once to prevent them from being used in other file units.
Referenced;

What is the difference between static local variables and common local variables: static local variables are initialized only once, and the next time is based on the previous result value;

What is the difference between a static function and a common function: a static function has only one copy in the memory, and a normal function maintains one copy in each call.

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.