0% found this document useful (0 votes)
2 views

Storage classes in cfa

The document explains storage classes in C programming, which define the scope, default initial value, and lifetime of variables. It details four main types of storage classes: Automatic, Static, Register, and External, providing code examples and their outputs for each. Understanding these classes is essential for managing variable behavior during program execution.
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)
2 views

Storage classes in cfa

The document explains storage classes in C programming, which define the scope, default initial value, and lifetime of variables. It details four main types of storage classes: Automatic, Static, Register, and External, providing code examples and their outputs for each. Understanding these classes is essential for managing variable behavior during program execution.
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/ 5

Storage classes are used to describe the features of a variable.

These
features basically include the scope, visibility and life-time which help
us to trace the existence of a particular variable during the runtime of
a program.

In C language, each variable has a storage class which decides the


following
things:
● scope i.e where the value of the variable would be available inside a
program.
● default initial value i.e if we do not explicitly initialize that variable,
what will be its default initial value.
● lifetime of that variable i.e for how long will that variable exist.
The following storage classes are most often used in C programming,
1. Automatic variables
2. External variables
3. Static variables
4. Register variables

Automatic variables: auto

Program:
#include <stdio.h>
int main( )
{
auto int j = 1;
{
auto int j= 2;
{
auto int j = 3;
printf ( "%d ", j);
}
printf ( "%d ",j);
}
printf( "%d", j);
}

Output :

3 2 1

Static variables: static

#include <stdio.h>
void display();
int main()
{
display();
display();
}
void display()
{
static int c = 1;
c += 5;
printf("%d ",c);
}

Output:
6 11

Register variables : register

#include <stdio.h>
int main( )
{
register int a=25;
printf("%d",a);
return 0;
}

Output:
25

External Variables : extern

File1.c
#include<stdio.h>
#include "file2.c"
extern int a;
int main()
{
printf("%d",a);
return 0;
}

File2.c
int a =50;

Output:
50

You might also like