Static, define, and const in C

前端 未结 9 2061
半阙折子戏
半阙折子戏 2020-12-13 04:52

I\'ve read that static variables are used inside function when one doesn\'t want the variable value to change/initialize each time the function is called. But what about def

9条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-13 05:23

    #define is a preprocessor operation and will cause all occurrences of m to be replaced by 30000 before the compilation phase happens. The other two examples are bona fide variables. The static variable exists in the translation unit in which it is declared and can be modified. The const variable is read-only.

提交回复
热议问题