About persistent storage, scope, links to sex, static and extern

Persistent storage : variable from the declaration to be destroyed.

  Continuous automatic storage: automatic variables (such as in the function int a;) is automatically persistence, the code block ({...} or the function) are created After execution of the function block or destruction, the memory is freed. As in the function (including main) declaration of an automatic variable, the function after the end destroy.

  Static storage duration of: an outer function (e.g., declared before main int a; additional functions can not be nested within the definition, i.e. the main function is no longer defined in a ) or static variables defined, they are stored in the program continuity the whole process (main) running there, but the scope will be different. Variables declared outside the function, his scope (say the following scopes) are available in the entire file (main.c or fun.c), that it can be used anywhere. And static variables declared in different regions of different scopes, when the function (e.g., main () Endo) or code segments, in this function is may be used anywhere, but in another function (e.g., in FUNC ()) is not visible unavailable.

  Dynamic Storage Sustainability: allocation on the heap, grasp the life cycle (or until the process of death) by the Bald Man who.

The scope and nature links : These two concepts are somewhat similar.

  Scope: in scope only used to describe the paper (e.g. main.cpp or a.cpp) of. Divided into global scope and local scope.

      Scope only used to describe a range within a file, said earlier static variables (static or outside a function declaration both ways), the outer functions as global scope, and when the static code section within a statement or function compared with the local scope.

  Links: the term used to describe the inter-file (as in main.cpp and a.cpp inter) action range. External links into resistance, internal links and links to free sex.

      Used to describe the scope of the links between different files. Said earlier static variable, the variable outside the function declaration, his link of the external links of the (global scope), that is, when declared outside the mian main.cpp file (), you can a.cpp in see and use. If the external function, but the use of static variables declared his internal links of links, that is only accessible in this document (he is also the global scope). If using static variables static declared his sexual link is not inside a function, that function can only be used within (his scope is local).

  Link scope of static generated in combination with:

    No static + = external links of the global

    static + = internal links of the global

    No link local static + = resistance

extern use : 

    extern for external tags that link of external links of variables, ie no static + global scope. extern mainly used to reference the external variables are as defined in a.cpp in an external variable sb, then use it to be used main.cpp extern when SB; described. Further references can also be noted sb main.cpp in scope, as referenced in a code segment, the outer segment of code is not yet available and is not visible. Referenced outside a function of the global scope can be used. When the definition of external variables, extern can be omitted, but can not be omitted when referring to, as a function outside a.cpp int sb = 100; this can be omitted, but must be added keyword extern referenced in the mian.cpp.

  

  

Guess you like

Origin www.cnblogs.com/lxy-xf/p/10986341.html