Variable storage class

C language based on the life cycle of a tag to differentiate, can be divided into static storage and dynamic storage.

  • Static storage : is assigned a fixed manner of storage space during program operation. Static storage area to store the variables throughout the program that are present, such as global variables.
  • Dynamic storage : means dynamically allocating storage space when needed during program execution. Dynamic variables stored in the storage area is established and released as needed to run the program, usually consisting of: functional form parameters; automatic variable; when the function call site protection and return address.

Language in storage class is divided into four categories:

  • Auto (auto),
  • Static (static),
  • Register (register)
  • External (extern).

 

1, with the keyword auto variables defined for automatic variables, can be omitted auto, auto write is not implied as "automatic storage class" is the dynamic storage.

2 with a modified static variables static, if the function is defined inside, called static local variables; if the external function is defined, called a static external variables. Static local variables as follows:

 

 Note: Static local variables are static storage class, in the static storage area allocated storage unit, the program is not released during the entire operation; static local variable initial value at compile time, that is, only one initial value;

If no initial value when defining a local variable, then the static local variable, the compiler automatically when the initial value 0 (for numeric variables) or null character (character variable).

4, with extern variable is declared external variables, external variables is the meaning of a function can be called after the variable definition of the function. Such as:

 

 

Internal functions and external functions (?)

    • Title can not function inside the called function other source files in the C language, the internal function is defined by the static keyword, it is also the title static functions, in the form of:
      static [Data type] function name ([parameters])
    • Here is a static scope defined function, the function is defined only in the source file is located, and therefore appear in different files in the same internal function name of the function is not a problem.
    • 在C语言中能被其他源文件调用的函数称谓外部函数 ,外部函数由extern关键字来定义,形式为:
      extern [数据类型] 函数名([参数])
    • C语言规定,在没有指定函数的作用范围时,系统会默认认为是外部函数,因此当需要定义外部函数时extern也可以省略。

Guess you like

Origin www.cnblogs.com/focusonoutput/p/12329556.html