C ++ - local variables, global variables, static variables and dynamic nature of the object (reprint)

 

 original:

https://blog.csdn.net/u013921430/article/details/79279114

 Outline

 

Local variables

       In a function of the internal variable defined (including function parameter), it is only effective within the scope of the present function , that is to say they are used only in this function, this function is outside of these variables can not be used, the type of variable is called "local variables."

       Local variables are stored in memory for the stack automatically destroyed at the end of the function.

Global Variables

       In vitro function defined variables, and may be other origin file functions well used, the effective range is defined starting from the position of origin to the variable end of file, the type of variables referred to as "global variables." Global variables are stored in static storage area (static RAM) .

       Global variables can be called after the declaration with extern in other files in the same project, it is saved every change you will.

Static variables

   Static global variables

       Static global variable is in front of the original plus a static global variable modified. Static global variables are still stored in the static storage area. The biggest difference with global variables is that static global variables can not be used by other source files, can only be used by source file , it is saved every change you will.

   Static local variables

       Static local variable is in front of the original plus a static local variable is modified. Static local variables are static and therefore stored in the static storage area , until the end of the process will be destroyed. But it is still scope within the function body. However, since the static local variable is defined, modify it each time will be saved.

Dynamic objects

      Dynamic allocation is the object of the program is running, such as the use of new and malloc allocated objects, this part of the lifetime of the object controlled by the program, that is to say, we need to manually dynamic objects are destroyed (using the delete and free for destruction) . Dynamic objects stored in the heap.

 

Guess you like

Origin www.cnblogs.com/east1203/p/11595184.html