For static variables and dynamic variables

Source: Internet
Author: User

(1) The following is a static global variable and a global variable example, but actually this is the same as the local variable principle

The global variable declaration is preceded by a static global variable. Both global variables and static global variables are stored statically, and there is no difference in storage. The difference is in their scope, the scope of the global variable is the whole source program, when the source program has multiple source files, the global variables are valid in each source program file, and the static global variable is limited scope, only in the source file that defines the variable is useful in the same program of other source files can not be used!

There are static global variables that are initialized only once to prevent calls in other source files! and global variables can be initialized with other source files!!
(2) So my understanding is static only in their own current file can be used, but for other files although they are in a project, but this variable can not be used, note that static variables can only be declared once,
However, a declared or defined dynamic variable can be used in any file under the same project.

For static variables and dynamic variables

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.