Deep understanding of the difference between C + + visibility and life time _c language

Source: Internet
Author: User

The visibility of the variable (that is, the scope) and the life period are both distinct and related.

A variable has no visibility at some point in the program, but the lifetime can exist, for example, the visibility of a local static variable in its function, outside the function is not accessible, but it is the lifetime of the entire program is running, and a variable lifetime end, it also has no visibility, like local variables, As the stack space is released, it does not exist, so it cannot be accessed externally.

Determining the visibility of a variable is where the variable is declared (just like a local static variable, because it is declared within a function, it can only be seen within a function, and the life of a variable is determined by its position in memory (as if the static local variable is not allocated on the stack, but is allocated in the memory-static storage area, Therefore the life period is also different from ordinary local 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.