“extern” inside a function?

后端 未结 3 1238
半阙折子戏
半阙折子戏 2020-12-31 00:51

Well, reading \"a bit old\" book (\"The C programming language\", second edition, by Dennis Ritchie), I came a cross the following:

An external variab

3条回答
  •  执念已碎
    2020-12-31 01:06

    extern int max inside main or function is saying to the compiler "I am not a local variable inside the main or function, I am the global variable defined elsewhere".

    If the global is declared in the same file, not useful. In different file,yes, but not in each function, just declare one time in the head file of the source that use this global variable. This is the same in c++.

提交回复
热议问题