Why does the global variable of VC still need extern?

Source: Internet
Author: User

Generally, you can define the global variable int inum in a CPP;

If you need to use this global variable in another CPP file, you must add a reference definition, such as extern int inum!



Suspect: since it is a global variable, it can be used in any file. Why should I add an "extern int inum" statement?


A: The scope of a global variable starts at the defined position and ends with the end of the file, that is, only the scope of the file. To extend the scope of global variables to multiple files, the extern keyword is provided in C ++. Extern keyword declaration, does not allocate memory.


Overview: Global
You also need to use extern to guard against it!

Reference: http://www.letuknowit.com/archives/87

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.