Variable scope in the field of Calvary

#include <stdio.h> // Scope: Where can access it
 // life cycle: an association of memory and time variables // global variables: define a variable outside of any braces is a global variable
 //     scope: scope of global variables is to define the location where the file to the end of [use extern in other files can be accessed]
 //     life cycle: run the entire program to the end of the program int g_number = 0 ;         // G (, Ltd. Free Join) is abbreviations global variable word // there are different assumptions scoped variables the same name, which will be used int Number the = 200 ;                     // L12 ~ L32 // static global variables: global variables modified using static
 //     scope: scope of global variables is to define the location where the file to the end, [but] can not access other files
 //     life cycle: run the entire program to the end of the program
 // can not be used to initialize a global variable when extern references to other documents already declared










extern  int g_number1;    
 // extern int g_number2;     

void Test () 
{ 
    // static local variables variables: using a modified static local variables
     //     scope: the same as ordinary local variables
     @     life cycle: the operation of the entire process ending the program 
    static  int n-= 0 ; 

    // a static local variables are initialized only the first one, after which the
     //     values are reserved before with 
    the printf ( " n-D =% \ n- " , n-++ ) ;
     // 0. 5. 4. 3. 1 2 
} 

int main ( void ) 
{ 
    // g_number1 = g_number2 = 10; 

    //Output is the global variable number, because this time it only see 
    the printf ( " Number D =% \ n- " , Number); 

    // local variables: variables defined in any one of the braces is the local variables
     //     scope : scope of local variables to define the position where the end braces
     @     life cycle: where the entering braces to leave braces 
    int number = 0 ;                     // of L19 ~ L31 

    @ output value of the local variable is a number, in this when there is the size of two
     //     scopes, and there is a variable of the same name, once this happens, the actual use
     //     is little scope variables. 
    the printf ( " Number D =% \ n- " , Number); 

    { 
        int Number = 0 ;                 // L12 ~ L13
        the printf ( " Number D =% \ n- " , Number); 
    } 

    for ( int I = 0 ; I < 10 ; I ++)     // L15 ~ L18 
    {
         int Number = 0 ;                 // L17 ~ L18 
    } 

    // C const constants language, using the value defined const must
     //     be initialized, and can not be modified during operation program 
    const  int n-= 10 ; 

    return  0 ; 
}

 

Guess you like

Origin www.cnblogs.com/lianfeng132/p/12358664.html