Unit 6 Part3
Unit 6 Part3
A)
Unit -6
Part3
Topics Covered in UNIT 6
➢ Storage classes
1. Type of storage classes
2. Example
Functions
Storage Classes: Storage classes define the visibility (scope) and the lifetime of any
function/ variable within a C program.
Type of storage classes
1. Automatic Storage Class
2. External Storage Class
3. Static Storage Class
4. Register Storage Class
Automatic Storage Class
Automatic Storage Class: It is also known as the auto storage class, and it acts as
the default storage class for all the variables that are local in nature.
Example:
External Storage Class: It is used for giving a reference of any global variable which
is visible to all the files present in a program. When using the extern storage class, we
cannot initialize the variable.
Example:
extern int x; // The compiler will start searching here if a variable x has
been defined and initialized in the program somewhere or not.
printf(“%d”,x);
int x = 20;
Static Storage Class
Static Storage Class: This type of storage class gives an instruction to a compiler to
keep the given local variable around during the program’s lifetime- instead of creating
it and then destroying it every time it comes into a scope and goes out of it.
Example:
Example: #include<stdio.h>
void sum() {
printf(“%d %d \n”,x,y);
X++; y++; }
void main() {
int a;
sum();
} }
Register Storage Class
Register Storage Class: We use the register storage class for defining the local
variables that must be stored in any register, and not in a RAM.
Example:
printf(“%d”,x);