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

Storage Classes in C 3

This document discusses the different storage classes in C - auto, extern, static, and register. It explains the scope, lifetime, initial value, and usage of each storage class. Auto variables are local variables with scope within the block, extern variables are global with scope throughout the program, static variables are similar to local but retain their value between function calls, and register variables are stored in registers for faster access but otherwise same as auto.

Uploaded by

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

Storage Classes in C 3

This document discusses the different storage classes in C - auto, extern, static, and register. It explains the scope, lifetime, initial value, and usage of each storage class. Auto variables are local variables with scope within the block, extern variables are global with scope throughout the program, static variables are similar to local but retain their value between function calls, and register variables are stored in registers for faster access but otherwise same as auto.

Uploaded by

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

Storage Class in C

I N T R O D U C T I O N
T Y P E S
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