answersLogoWhite

0


Best Answer
AnswerLocal Variables are stored in Stack. Register variables are stored in Register. Global variables are stored in data segment. The memory created dynamically are stored in Heap And the C program instructions get stored in code segment and the extern variables also stored in data segment.

Nooo Nooo

Static variable will be stored in .BSS segment... (Block Started By Symbol)

User Avatar

Wiki User

10y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

8y ago

Extern is not a storage allocation specifier, it declares external linkage. That is, the declared variable or constant will be defined in a separate translation unit.

Variables declared in global scope are allocated in static memory, as are all constants and static local variables.

Local (non-static) variables are allocated on the (current) call stack. In multi-threaded applications, each thread has its own call stack.

Register variables are automatic variables allocated within a CPU register, however the language compiler ultimately decides when or indeed if this is appropriate.

This answer is:
User Avatar

User Avatar

Wiki User

16y ago

Global variables don't have special place where it can be stored in. OS decides where to save it. Global variables are special only in the way that all blocks of your program can get access to it.

This answer is:
User Avatar

User Avatar

Wiki User

14y ago

That's just it, where they are stored is not defined in the current file.

For example, if you have one file, a.c, that declares:

extern int foo;

That means that this file has no clue where the variable is declared.

For the program to compile properly, you'll need to have another file, b.c, that declares:

int foo;

This answer is:
User Avatar

User Avatar

Wiki User

10y ago

RAM = Random Access Memory

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is the storage allocation and scope of global extern static local and register variables?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What are the storage classes in c?

A storage class defines the visibility and lifetime of variables or/and functions within a C Program. There are following storage classes which can be used in a C Program: auto register static extern


Auto static extern register?

Storage classes.


What is meant by the storage class of a variable?

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


What is storage classes in c plus plus?

AUTO EXTERN STATIC are the storage classes in c++


What is different storage class in c?

Different from what? Storage classes are auto, register, static, extern and typedef (formally).


Why you need to declare auto storage class specifier in c language?

We don't. The auto storage class is the default storage class for all local variables and is therefore completely redundant in C. It exists for no other reason than that C evolved from B and inherited all its storage classes (auto, static, extern and register).


Storage classes available in c language?

There are four types of storage class or variable in c. 1) auto storage class. 2) register storage class. 3) static storage class. 4) external storage class.


Do you specify a storage class with typedef?

In C, "typedef" is a storage class, but sort of a weird one. It specifies that you are not actually creating an object, but merely defining a type. As such, there is nothing to be stored (at runtime). The other storage classes, auto, extern, register, and static, all specify actual storage.


What is the utility of storage class in c?

In C there are four storage classes: auto, static, extern and register. These storage classes essentially define the scope or visibility of a name (a function or variable). All four are inherited from B, the language from which C evolved.The auto storage class is used to explicitly declare a non-static local variable. However, given that all non-static local variables are implicitly automatic in C, explicit use of the auto storage class is therefore redundant in C. Moreover, in C++11, explicit use of the auto storage class was dropped entirely; the auto keyword is now used for automatic type deduction in C++.The static storage class is used to explicitly declare a static local variable. In addition, all global variables and functions are implicitly static and have external linkage, but if explicitly declared static they have internal linkage only.The extern storage class is used to allow access to a name that has external linkage.The register storage class is used to define a variable that should be allocated in a CPU register rather than in working memory (RAM).


What value is assigned to extern variable?

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


What is a register variable in c programming?

A register variable is a variable that we wish to allocate in a CPU register rather than in a memory address (RAM). Register variables must be less than or equal in length to the word length of a CPU register which typically limits their use to integral types and pointers. Typical uses for register variables include counters, accumulators and other regularly-accessed variables within a localised code block. Storage classes were originally inherited from B, however only the static and extern storage classes have any meaningful purpose in C. The register storage class is largely redundant while the auto storage class is wholly redundant. Explicitly declaring a register variable is no guarantee the variable will actually be allocated to a register, it is merely a hint to the compiler that the variable is a candidate. However, modern compilers are perfectly capable of determining which variables make good candidates without hints, so there is typically no need to explicitly declare them. If we have more good candidates than there are registers available, explicitly declaring our preferred candidates might be considered worthwhile, however it's generally better to just let the compiler decide. Note that register variables have no memory address. If we take the address of any variable using the unary '&' operator, then that variable can no longer be considered as a register variable candidate by the compiler. If we explicitly declare a register variable and subsequently attempt to take its address, the compiler will issue a warning, yet another reason to simply let the compiler decide.


Is global variables are declared within the main function?

Might be, but don't forget the keyword 'extern':int main (void){extern int errno;...}