answersLogoWhite

0


Best Answer

External Variables are declared outside all functions, yet are available to all functions that care to use them.

Features of external variables :

Storage : Memory

Default Initial value : zero

Scope : Global

Life : As long as program's execution does't come to an end

User Avatar

Wiki User

13y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is the use of extern variable?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Math & Arithmetic

Why is x always be a variable?

It is very common to use, but it is not the only variable you can use.


What variable do you use to represent the lateral surface area?

You can use any variable that you want.


What is the variable for 500?

there is no variable for 500, but you could use the most commonly known variable X.


What is the difference between declaring variable and initializing variables?

Actually, there is a third step, call definition. Declaration is a statement to the compiler of what type an identifier is, definition is the allocation of memory for that identifier, and initialization is the assignment of an initial value to that identifier. Usually, declaration and definition are done together, but you can also add initialization in that step if desired. int a; /* declaration and definition */ a = 1; /* initialization */ int a = 1; /* declaration, definition, and initialization */ For the case of seperate declaration and definition, consider the struct... struct _mystruct { int a; }; /*declaration */ struct _mystruct mystruct; /* definition */ struct _mystruct { int a; } mystruct; /*declaration and definition */ Note: To be more precise: struct _mystruct; /* struct declaration */ struct _mystruct { int a; }; /* struct definition */ typedef struct _mystruct MYTYPE; /* type definition */ extern struct _mystruct mystructvar; /* variable declaration */ struct _mystruct mystructvar; /* variable definition */ struct _mystruct mystructvar = {7} ; /* variable definition with initialization */ struct _mystruct { int a; } mystruct; /* struct definition and variable definition */ extern struct _mystruct { int a; } mystruct; /* struct definition and variable declaration */


How do use substitution when solving system of equations?

You use substitution when you can solve for one variable in terms of the others. By substituting, you remove one variable from the equation, which can then be solved. Once you solve for one variable, you can use substitution to find the other.

Related questions

What is extern C used for?

extern specifies that the variable is in another file.say you have a variable(int k = 10) in mycpp1.cpp and you want to use it in mycpp2.cpp use the extern to redeclare the variable and use it.Example:Code://mycpp1.cppint k = 10;Code://mycpp2.cppextern int k;void function(void){cout


What value is assigned to extern variable?

Default initial value of extern integral type variable is zero otherwise null.


How do you write a program to illustrate the concept of extern variable?

In order to use extern you have to have at least two files. In first one, let's call it file1.cpp, you will define a variable using extern (in this case belongs to int):...extern int myVar = 0;...Then in file2.cpp file where you have main() you need to write following:extern int myVar;Do not initialize the variable in file2.cpp, or you code will not compile.


Difference between int a and extern int a. why the first one is definition while the second is declaration please explain?

The declaration 'int a' both declares the variable of 'a' and allocates memory for it. When you use 'extern' you are referring to a variable called 'a' that has its memory allocated in another module. The actual variable 'a' is not in the same compilation unit as the current one being compiled. Where the variable 'a' is located is resolved by the linker. When using 'extern' you state your intent to use a variable called 'a', but it doesn't reserve any memory for it in the current module.


How do you access extern variable in c?

The usual method: with its name: extern int errno; errno= 17;


What is Variable declaration and variable initialization?

...are important things in programming. Example: extern int variable; /* declaration */ int variable= 8; /* definition with initialization */


Is possible define a structure with extern keyword?

extern is used only when there is a variable or a function name. so here's what you can do, typedef struct{ int data; }my_struct; extern my_struct my_new_struct; Compilers takes this as a *type*.


What is meant by the storage class of a variable?

auto, extern, static, register, typedef (only formally)


What is external variable in c language?

The "extern" declaration in 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 modules (a single C module is typically a single .c file). An extern is something that is defined externally to the current module. In many cases, you can leave off the extern qualifier and not notice any difference because the linker can collapse multiple definitions to one. But the intent is then unclear in the code, and the code is error prone in case of typos. It is much clearer to define the global in one place, and then declare extern references to it in all the other places. When refering to globals provided by a library, especially a shared library, this is even more important in order to ensure you are talking about the correct, common instance of the variable. Declaring a variable as extern will result in your program not reserving any memory for the variable in the scope that it was declared. For instance (as example) if a program's source code declared the variable var as a global volatile int in foo.c, to properly use it in bar.c you would declare it as extern volatile int var. It is also not uncommon to find function prototypes declared as extern. A good C manual will certainly answer this more completely.


What is the difference between global and extern?

AnswerGlobal variables and extern variables are very similar, but with a major difference. Let's say you have a global variable in your header file, like this:( Refer how u can add the variable declaration in the source code as extern, i think we cant add into header files as it said)int x = 0;Now, in each file that includes that header file, there will be a new variable called x. Modifying x in file1.cpp won't modify x in file2.cpp.Now, for externs... Say you have something like this in your header:extern int x;Then, in file1.cpp (which includes your header):int x = 0;Then, in file2.cpp (also includes the header):x = 46;x in file1.cpp is also now equal to 46. You see, when you use an extern variable, you're telling the compiler that you want to use that variable across all of your source files. If you use a regular global, however, you create a new variable in each of your source files.Anyway, that's just for variables, which I assume you're talking about - global and extern functions are a bit different, and I'm not entirely clear on them.


How java use extern key word which is used in C plus plus?

No extern keyword in Java.


Which is the keyword used to access the variable declared as global variable in another file?

To be able to access a variable declared in one file/class from another file/class you need to declare that variable as "public". Doing this is a very bad coding practice because exposing a variable of a class to be available publicly to other classes is totally against the Java object oriented concepts of Encapsulation and Data hiding. So, preferably you shouldn't be doing this. However, a better way to do this is, declare the variable as private and have public accessor methods through which you can access this variable. This will ensure that your data is protected even if it is available outside the class