Static usage in C Language

Source: Internet
Author: User

Static can be used to modify variables or functions in c.

 

1. static local variables
A. lifecycle: static local variables are defined in the function, and the lifetime is the entire source program;
B. Storage Method: When static modification is used, the storage from the original stack is changed to static storage zone;
C. Scope: it is the same as an automatic variable and can only be used in the function defining the variable. After exiting the function, although the variable still exists, it cannot be used;
D. initialization: if an initial value is not assigned to a static local variable of the basic type, the system automatically assigns a value of 0. If an initial value is not assigned to an automatic variable, the value is not fixed.

 

2. static global variables
A. Storage Method: global variables are static storage methods, and static global variables are also static storage methods;
B. scope: the scope of a non-static global variable is that multiple source files of the entire source program can be used together), while a static global variable limits its scope, that is, it is valid only within the source file that defines the variable.

 

3. static Functions
It can only be called by functions in this file, but not by functions in other files of the same program. Different from external functions of non-static functions ).

 

This article is from the "Sun's technology blog" blog, please be sure to keep this source http://sunke.blog.51cto.com/4812218/1282566

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.