C++ static members and static functions (non-class)

For variables modified by the normal static keyword

Life cycle: from the beginning to the end of the program, the memory is in the heap, which has been allocated before the program runs (regardless of the global and local)

scope:

  • Global static variables: only apply to the current source file, it is not easy to use this source file, and ordinary global variables can still be accessed by adding extern in another source file
  • Local static variable: only inside the scope function, but except for the function, the value still exists and will not be destroyed. Ordinary static local variables will not be destroyed

There is a picture that sums it up very well, refer to the linked blog

The scope of variables (global variables, local variables and static variables)

The summary graph section in

To see the actual code understanding, read this blog:

C++ static and its scope - kouei_kou - 博客园

Guess you like

Origin blog.csdn.net/qq_31638535/article/details/128718304