On local and global static variables in C++

前端 未结 7 1068
野的像风
野的像风 2020-11-29 05:55

C++ Primer says

Each local static variable is initialized before the first time execution passes through the object\'s definition. Local statics are

7条回答
  •  遥遥无期
    2020-11-29 06:17

    1. They are known to all functions in a program whereas global variables are known only in a limited scope.
    2. Global static variables can be initialized before the program starts whereas local static variables can be initialized as execution reaches point.

提交回复
热议问题