Questions tagged [extern]

extern is an access-specifier in C and C++ which defines a global variable that is visible to all object modules.

The extern keyword means "declare without defining". In other words, it is a way to explicitly declare a variable, or to force a declaration without a definition. The extern declaration in C/C++ is to indicate the existence of, and the type of, a global variable or function. A global variable, or a global function, is one that is available to all C/C++ modules. An extern is something that is defined externally to the current module.

schematic representation of global variable declared with extern keyword (source)

1475 questions
-5
votes
4 answers

What is the exact meaning of the "extern" statement in c++?

I would just like to know what the "extern" statement is used for in c++, and when/why it is used?. Thanks.
zamfir
  • 161
  • 7
-6
votes
1 answer

Extern and usage with examples

Alright, this question is really meant to provide usage of extern with examples in c++.
user2438870
-7
votes
10 answers

How can I use a class from a header file in a source file using extern but not #include?

If I have a class in outside.h like: class Outside { public: Outside(int count); GetCount(); } How can I use it in framework.cpp using the extern keyword, where I need to instantiate the class and call GetCount? Edit: #include is…
Joan Venge
  • 315,713
  • 212
  • 479
  • 689
-8
votes
2 answers

Why doesn't the "extern" keyword work in the same file?

Please see the below example code for the use of "extern". When I use the extern keyword in my code, I get a compilation error. Please suggest a solution for the problem. #include extern int x; extern int y; extern int z; int…
saien
  • 5
  • 4
-10
votes
1 answer

extern type declaration conflict in C

int main() { extern long long a; a=100000000000; //10 raised to power 11 printf("%lld",a); return 0; } int a; Output: 100000000000 int a means definition, which will allocate 4 bytes to variable a, but extern long long a is…
1 2 3
98
99