The role of static in C language

Source: Internet
Author: User

(1) In the function body, the local static variable. The lifetime is the entire life cycle of the program, but the scope is within the defined function body. A variable declared as static maintains its value in the process of the function being called. Because it is allocated in a static storage area, the function call does not release the unit after it is finished, but it cannot be accessed at other scopes. When this function is called again, the local variable survives and is used in its access space, so it accesses the value after the last call.

(2) within the file module but outside the function body, a global variable declared as static can be accessed by all functions within the module, but not by other functions outside the module, which is a local global variable that restricts the scope of the static global variable.

(3) Within a file module, a function defined as static can only be called by other functions within the module. In other words, this function is limited to the use of this file module, the function is a global function by default, can be called by any other file module.

The role of static in C language

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.