Why does declaring an extern variable inside main() works,but not defining it inside main() as well?

后端 未结 4 1331
悲哀的现实
悲哀的现实 2021-01-14 04:29

This seems very trivial but a somewhat rigorous explanation for the following behavior will help my understanding of extern a lot.So I\'ll appreciate your answe

4条回答
  •  执念已碎
    2021-01-14 05:04

    Nobody uses extern in this way. extern is usually used on big projects, lots of .c , .h files and some variables needs to be shared. On those circumstances, compilation often fails to resolve variable declaration (perhaps, it's on some .h file which yet to compile), then "extern" is used to tell compilar to leave it for now and proceed compilation, this thing will be dealt at linking phase.

提交回复
热议问题