Storage Classes
Storage Classes
STORAGE CLASSES
Introduction
Types of storage classes
classes
INTRODUCTION
To declare and define a variable we need to
specify the datatype. But , to fully declare a
variable, it is also important to specify the
storage class.
If we don’t specify a storage class of a
Automatic Variables
External Variables
Static Variables
Register Variables
AUTOMATIC VARIABLES
Automatic variables are declared inside a
function(block) in which they are used.
Keyword used to declare a automatic
variable is auto .
Auto variables are stored in memory.
variables
AUTOMATIC VARIABLES CONTINUE…
void main()
{
auto int i;
printf(“ i: %d”,i);
}
extern.
Extern variables are stored in memory.
Scope is global
program is executed.
These are also referred as global variables
EXTERAL VARIABLES CONTINUE…
int i;
extern int i;
void main()
{
printf(“ i: %d”,i);
}
Output: 0
STATIC VARIABLES
Static variables can declared either internal
or external .
Keyword used to declare static variable is
static.
Extern variables are stored in memory.
declaration.
Lifetime of internal static variable is local to
register.
Extern variables are stored in CPU registers.
register int i;
for(i=1;i<=5;i++)
printf(“ i: %d”,i);
}
because it is limited*/
OVERVIEW
Storage Keywor Storag Default Scope Lifetime
Class d e initial
value
Automati auto memory Garbage Local to With in the block
c the
block
External extern memory Zero Global Till the end of
program exe
Static static memory Zero Local Value of the
variable persists
b/w diff. function
calls
Register register CPU Garbage Local to With in the block
register the
block