What does “static” mean in C?

后端 未结 19 1900
误落风尘
误落风尘 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:34

    It is important to note that static variables in functions get initialized at the first entry into that function and persist even after their call has been finished; in case of recursive functions the static variable gets initialized only once and persists as well over all recursive calls and even after the call of the function has been finished.

    If the variable has been created outside a function, it means that the programmer is only able to use the variable in the source-file the variable has been declared.

提交回复
热议问题