On local and global static variables in C++

前端 未结 7 1076
野的像风
野的像风 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:31

    Their scope is different. A global-scoped static variable is accessible to any function in the file, while the function-scoped variable is accessible only within that function.

提交回复
热议问题