What does “static” mean in C?

后端 未结 19 1958
误落风尘
误落风尘 2020-11-21 05:18

I\'ve seen the word static used in different places in C code; is this like a static function/class in C# (where the implementation is shared across objects)?

19条回答
  •  爱一瞬间的悲伤
    2020-11-21 05:20

    If you declare a variable in a function static, its value will not be stored on the function call stack and will still be available when you call the function again.

    If you declare a global variable static, its scope will be restricted to within the file in which you declared it. This is slightly safer than a regular global which can be read and modified throughout your entire program.

提交回复
热议问题