answersLogoWhite

0


Best Answer

Basically storage class defines the accessibity of a variable. If you specify a variable with auto storage class, then that variable can be accessed only in that function or block where it is declared. if you specify a variable with static storage class, it has the same visibily like an auto variable but it can retains it's value between function calls where as an auto variable cannot. look at this example: void main() { int i,j ;

for(j = 0; j< =2; j++) { i = fun1(); printf("%d",i); } } int fun1() { static int k =0; k = k+1; return k; } it prints 1 2 3

User Avatar

Wiki User

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

Wiki User

7y ago

Storage classes were originally inherited from the B programming language (the language from which C evolved). There are four storage classes: automatic, external, registerand static. The exact meaning of these storage classes depends on whether they are implicitly or explicitly declared and in what context they are used.

All local variables, including formal arguments, have automatic storage by default. All this really means is that they are allocated on the call stack. Given this is done automatically for all local variables and formal arguments, we do not need to specify the automatic storage class; it is implied. The auto keyword serves no other purpose in C so we seldom see it in production code, if at all. Its presence in the language is historical rather than functional.

Local variables (but not formal arguments) can be explicitly declared static. Static local variables are allocated in the program's data segment and are accessible to all instances of the function in which they are declared whereas automatic variables are only accessible to the current instance of the function. Being allocated in the data segment also means the variable is accessible outwith the scope of the function in which it is declared. However, this is best avoided in multi-threaded applications as it can result in data races.

Local variables and formal arguments can also be explicitly declared with the register storage class. Register variables are allocated in a CPU register rather than on the call stack. This can be useful for counter variables within for loops, accumulators or other variables that are accessed often. Register variables have no memory address so we must not attempt to take the address of a register variable. The variable also has to be small enough to fit in a register. However, the register storage class should only be regarded as a (strong) hint to the compiler rather than an explicit directive. There are a limited number of registers available so we cannot declare every automatic variable as a register variable, however the compiler's optimisers are perfectly capable of deciding which variables should be register variables and which should be automatic.

All global variables are static by default. This means is that the variable is allocated in the program's data segment (as with local static variables). Again, this is implied, however the meaning changes when we explicitly declare a global with static storage. When we do this we limit the scope or visibility of that global to the file in which it is declared. It is still global but it only has internal linkage. If static storage is implied, then it has external linkage.

When we declare a global variable with external storage we are not actually allocating any storage at all, we are simply declaring that the global variable is (or will be) defined in another translation unit.

All functions have global access with external linkage by default but we can limit their scope to the file in which they are declared by declaring them static, as per global variables. We do not use the external storage class with functions.

Note that since C++11 (ISO/IEC 14882:2011) the auto keyword has been redeployed such that an object's type can be deduced from its initialiser (automatic type deduction). Automatic storage can also be used in range-based for loops, typically when iterating over a container's objects. Trailing-return-types also make it possible for template functions to deduce return types from incomplete types. These redefinitions will never be migrated to the C Programming language without fundamental changes to the language itself.

This answer is:
User Avatar

User Avatar

Wiki User

14y ago
There are four storage classes in c

a) auto

b) register

c) static

d) extern

This answer is:
User Avatar

User Avatar

Wiki User

13y ago

In c static and global variables are stored in data segment ( which is a special memory in RAM)

This answer is:
User Avatar

User Avatar

Wiki User

13y ago

Extern is not storage class.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is static extern variables in C?
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


What is storage classes in c plus plus?

AUTO EXTERN STATIC are the storage classes in c++


How i useStatic extern int a in c?

No such thing, pick one ot the three: static int x; extern int x; int x;


What are Static variables in c?

A static variable in C is a variable whose value and memory allocation persists throughout the execution of the program. If the variable is declared at file scope (outside of any blocks) the static attribute means the variable is visible only to the file containing it, i.e. it can not be referenced through an extern reference in a different file.


What is the difference between extern and global?

Extern and Global are the storage space in C program. Global provides us to access the variables from anywhere inside the program only whereas Extern provides us to access the variables from outside that program, i,e., some other program.


What is different storage class in c?

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


Are C variables initialized to 0 by default?

Only global/static variables are, local variables aren't.


Auto static extern register?

Storage classes.


What is meant by the storage class of a variable?

auto, extern, static, register, typedef (only 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).


Can static variables be declared in header file?

Can static variables be declared in a header file?You can't declare a static variable without defining it as well (this is because the storage class modifiersstatic and extern are mutually exclusive). A static variable can be defined in a header file, but this would cause each source file that included the header


What does extern C stand for?

"extern" is short of "external" which means outside.