Storage Internal variables

  1. Memory: physical memory, virtual memory

    • Physical Memory: real storage exists

    • Virtual memory: the operating system out of the virtual memory

    • The operating system will do the mapping between physical memory and virtual memory

    • In the 32-bit addressing range for each process system is 4G; 0x00 00 00 00 ~ 0xff ff ff ff

    • In writing the application, we see all virtual memory

  2. When running the program, the operating system will be the virtual memory partition

    • stack

      • When dynamic application memory, the memory on the heap open

    • Stack

      • The main store local variables

    • Static Global Area

      • Uninitialized static global area

        • Static variables (defined variable, preceded by static modification), or global variables, uninitialized, the existence of this area

      • Initialize static global area

        • Global variables, static variables, the initial value is assigned too, placed in this area

    • Code area

      • Our store program code

    • Literals area

      • Storage of constants

  3. General global variables

    • concept:

      • Function externally defined variables

      • int num = 100; // num is a global variable

      • int main () {

      • return 0;

      • }

    • Scope

      • Scope of global variables, all of the local programs

      • But with the need to declare before declaring the method extern int num;

      • Note that statement, do not assign.

    • The life cycle

      • The whole process of running the program, there has been, until the end of the program

    • Note: ordinary global variables defined time, if no initial value, its default value is 0;

  4. Static global variables static

    • concept

      • Define global variables when the front with static modification

      • static int num = 100; // num is a static global variable

      • int main () {

      • return 0;

      • }

    • Scope

      • defining a static global variable static scope

      • Only (source files) are effective in .c its definition

    • The life cycle

      • In the entire run of the program, there has been

    • Note: The definition of static global variable, if no initial value, its default value is 0;

  5. Ordinary local variables

    • concept

      • Defined in function of the internal variable defined, or a compound statement

      • int main ()

      • {

      • int num; // local variables

      • {

      • int a; // local variables

      • }

      • }

    • Range:

      • Variables defined in the function, the function is valid

      • Defined in the compound statement, the compound statement is valid

    • The life cycle

      • Before the function call, local variables do not take up space, call the function when it opened up space for local variables, function is over, local variables on the release

      • The same compound statement

  6. Static local variables

    • concept

      • Define local variables when preceded static modification

    • Scope

      • Active compound statement or a function that defines the

    • The life cycle

      • The first function is called when the open space assignment, after the end of the function, it will not be released

      • Later call the function when it is no longer its open space, nor initial value, using a variable that previous

    • note:

      • General definition of local variables, if no initial value, the value is random

      • Defines static local variables, if no initial value, its value is 0

      • General global variables and static global variables, if no initial value, its value is 0

  7. Variables are duplicate names

    • Scope is not the same, variable allows the same name, equivalent to some first with his own, then he did the others (in the case of global variables, or nested functions)

  8. External function

    • Let ordinary function definitions are external functions.

    • That function can be any of a file and then call the program

  9. Internal function

    • Then function defined functions, the return value preceded static modification, such a function is referred to as an internal function.

    • defining a reach static function, it is defined in the .c, not available elsewhere

    • The difference between internal and external functions of the function

      • External functions can be invoked in all places

      • Internal function, can only function calls in .c defined in

    • In the same scope, the variables are not allowed the same name

    • Of the same name may be different scope

    • A local scale, the same name of the global variable ineffective. (Went into the principle) that is first with their own, with others

Guess you like

Origin www.cnblogs.com/fengzi759/p/11618700.html