What is the use of extern in declaring constants?

can please tell me what is the use of extern variable when declaring the constant variables in different file.

Answers


The extern keywords forces the compiler to treat the statement as a declaration rather than a definition. In other words, extern prevents the compiler from reserving space for the variable. Thus, only the compilation unit which does not use extern provides a definition, while the others merely use the declaration, which is in keeping with the "one definition rule"; if each compilation unit were to reserve space independently for the same variable, it would result in a violation of the "one definition rule". Note that extern literally means that "the definition is provided externally (by a different compilation unit)".


Just like C, extern keyword means that the symbol is defined in another object file that will be linked to this one in compilation phase.


Need Your Help

Ivy: how do I remove transitive dependencies?

ant dependencies ivy

I'm using Ivy to manage the dependencies on my project.

Quicksand.js interfering with Bootstrap Modals

javascript twitter-bootstrap twitter-bootstrap-3 bootstrap-modal quicksand

I've been trying to make a lightbox portfolio using the Bootstrap Modal functions, with the quicksand sorting plug-in. I originally followed this tutorial which I had to work with a little to get t...