Difference between Static variable declared in different scopes

后端 未结 6 983
梦谈多话
梦谈多话 2020-12-19 12:27

What is the difference between declaring static variable inside a block and outside a block in a file? Eg, here, what is difference between static variables a,b,c,d? Can we

6条回答
  •  余生分开走
    2020-12-19 12:47

    Static variable inside a block(local static variable) -

    1. It is not visible outside the block/function
    2. It's value retains in function calls as it is static

    Static variable outside a block(Global static variable) -

    1. It's scope is the entire file(like a in your program)
    2. It's value retains between function calls as it is static.

提交回复
热议问题