0% found this document useful (0 votes)
38 views11 pages

Storage Class in C: Types

Storage class in C determines the scope, lifetime, and initial value of variables. There are four storage classes: auto, extern, static, and register. Auto variables are local variables with scope within the block, lifetime until the block ends, and garbage initial values. Extern variables have global scope and lifetime until the end of the program with initial value of 0. Static variables are like local variables but retain their value between function calls and have lifetime through the program. Register variables are stored in registers instead of memory for faster access.

Uploaded by

Muzamil Basha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views11 pages

Storage Class in C: Types

Storage class in C determines the scope, lifetime, and initial value of variables. There are four storage classes: auto, extern, static, and register. Auto variables are local variables with scope within the block, lifetime until the block ends, and garbage initial values. Extern variables have global scope and lifetime until the end of the program with initial value of 0. Static variables are like local variables but retain their value between function calls and have lifetime through the program. Register variables are stored in registers instead of memory for faster access.

Uploaded by

Muzamil Basha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 11

Storage Class in C

INTRODUCTION
TYPES

Introduction
Storage class explain the behavior of the variable in

terms of scope and lifetime, it also determine the


initial of the variable.
Scope of the variable is the region over which the
variable is visible or valid.
Life time of the variable is the time during which
memory is associated with the variable.
Initial value is the value assigned to the variable
implicitly if no value is assigned to it by the
programmer.

There are four types of storage class available in C:

Auto
Extern
Static
Register

Auto
All local variables has this storage class.
Default value is the garbage value.
Scope of the variable is only between the blocks

where it is declared.
Lifetime is till the control remains within the block
or function where these variables are defined.
These variables are destroyed whenever block ends
or function jump occur.
To declare auto storage class auto keyword is used.

Example:

auto int n;

Auto keyword is optional all the local variables by

default fall under this storage class.


Example:

int n;

Extern
Scope is through out the program.
Lifetime is till the end of the program.
Initial value is 0.
Extern keyword is used to declare the variable of this

storage class.

extern int x;

By default global variable has this storage class.

Static
It is special case of local variable.
These are defined inside the function or block.
Its scope is inside the block or the function where it

is defined.
Initial value is 0.
Its value is retained between different function calls.
Lifetime is same as the global variable i.e. through
out the program.
Keyword static is used to define this type of variable.

Register
Register variable behave in every way same as the

auto variable.
The only difference is that register variable are store
inside the computer register instead of the memory.
They are used when CPU has to access the variable
very frequently. Eg looping variable
They are defined by placing keyword register before
the datatype of variable. Example

register int a=10;

You might also like