C/C ++ extern

Source: Internet
Author: User
Extern is the global variable declaration. As long as the global variable is declared, extern is added first by default (the programmer can not add it, but the compiler adds it by default)
If this file references global variables in other files, you must add the extern declaration.
By default, the function has extern before its declaration and definition. For example, when we declare a function,

Int Foo (INT arg1, char arg2 );
There is an implicit extern before the function, and the compiler processes it
Extern int Foo (INT arg1, char arg2 );

The definition of global variables is generally placed in the source file. If it is placed in the header file, it is likely that the definition will be repeated.
After a global variable is defined, you can place the declaration in the corresponding source file, and other files can include the header file when using the variable.
If you do not want to include the variable (you only want to use this variable and do not need to include it), you can declare this variable using extern.
Global variables and global functions are defined with extern by default. Even if the programmer does not add it, the compiler will add it.

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.