The static keyword in C + +

Source: Internet
Author: User

1. In the function body, a variable declared as static maintains its value in the process of the function being called.

2, within the module (but outside the function), such as in a certain C source file, a variable declared as static can be called by all functions within the module, but not the function called outside the module.

He is a local global variable.

3. Within the module, a function declared as static can only be called by a function within that module.

The difference between a static local variable and a normal local variable is that the static local variable is initialized only once, and the next time it is based on the last result value.

The difference between a static global variable and a normal global variable is that the static global variable is initialized only once, preventing it from being referenced within other files.

The difference between the static function and the normal function is that the static function has only one copy in memory, and the normal function maintains a copy of each call.

The static keyword in C + +

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.