External variable extern in C Language

Source: Internet
Author: User

The C language Storage types include extern, auto, static, and register.

External variables are defined outside the function, and all references to external variables through the same name (even if such references come from different functions compiled separately ), in fact, all references to the same external variable are referenced (this property is called an external link in the C standard ). Therefore, external variables can be accessed globally.


GetChar. c:

# Include
# Include
Extern char str []; // do not declare it in the header file
Int index_str = 0;
Char getChar (){
Return str [index_str ++];
}


GetStr. c:

# Include
# Include
Char str [255];
/* Get the testfile string */
Void getStr (char * filename ){
Int index = 0;
FILE * fp;
If (fp = fopen (filename, "r") = NULL ){
Printf ("open test_file fail !!! \ N ");
Exit (1 );
}
While (str [index ++] = getc (fp ))! = EOF );
Str [index] = '\ 0';/* end sign */
Fclose (fp );
}


Http://blog.csdn.net/pipisorry/article/details/25346379

Related Article

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.