What does “static” mean in C?

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

    If you declare this in a mytest.c file:

    static int my_variable;
    

    Then this variable can only be seen from this file. The variable cannot be exported anywhere else.

    If you declare inside a function the value of the variable will keep its value each time the function is called.

    A static function cannot be exported from outside the file. So in a *.c file, you are hiding the functions and the variables if you declare them static.

提交回复
热议问题