Definition of extern in C++
extern specifier is used in variable and function declarations (except class members or function parameters). It specifies external binding and does not technically affect storage duration, but it cannot be used in a definition of an automatic storage duration object, so all
extern objects have static or threaded durations.
This is useful when you have global variables and declare their existence in a header so that every source file that includes the header knows about it, but you only need to “set” it once in one of your source files .
Example, Suppose you have 3 files and you will link two files:
After compiling the output will be: 9.36, but available for all files.
Suppose you are writing a plugin/extension for a program written C, but you are using C++, so you can change the context of your code to C .
If a program is written in C it will work with this code, even using classes, constructors, destructors, namespace,…
That’s all for today, small daily doses that will always keep us in tune with C++!