Declarations and definitions c ++ (3) ---- variables

Separate compilation (separate compilation):

  Allow the program is divided into several files, each file can be compiled independently.

        Disclaimer: making known the name of the program.

        Definition: responsible for creating an entity associated with a name.

   Variables can be defined only once, but can be declared more than once.

If you want to use the same variable in multiple files, it is necessary to separate the declaration and definition. In this case, the definition of variables must appear and only appear in one file, while others use the variable file must be declared. 

extern  int i;    //   declare i not defined i 
int J; // declare and define 
int C = . 3 ; // declaration definition, initialization 

extern  int K = . 3 ;    // definition of the role at this time is canceled extern 

/ / inside the function body, if you try to initialize a variable marked by the extern keyword, throws an error

 

Guess you like

Origin www.cnblogs.com/feihu-h/p/12237877.html