You are on page 1of 4

// the concept of local variable or auto storage

class.
#include<stdio.h>
#include<conio.h>
void display();
void main()
{
auto int a; // auto keyword is optional.
clrscr();
printf("\nin main address of a is %u",&a);
printf("\nthe value of a is %d",a);
a=5;
printf("\nthe value of a is %d",a);
display();
printf("\nthe value of a is %d",a);
display();
printf("\nthe value of a is %d",a);
getch();
}
void display()
{
auto int a;
printf("\n\nin display address of a is %u",&a);
a=10;
printf("\n\nthe value of a is %d",a);
}

// the concept of global variable or external storage class.


#include<stdio.h>
#include<conio.h>
extern int a; // extern keyword is optional
void display();
void main()
{
clrscr();
printf("\nin main address of a is %u",&a);
printf("\nthe value of a is %d",a);
a=5;
printf("\nthe value of a is %d",a);
display();
printf("\nthe value of a is %d",a);
display();
printf("\nthe value of a is %d",a);
getch();
}

void display()
{
printf("\n\nin display address of a is %u",&a);
a = 10;
printf("\n\nthe value of a is %d",a);
}

//the concept of static storage class


#include<stdio.h>
#include<conio.h>
void display();
void main()
{
clrscr();
int a=1;
a++;
printf("\nthe value of a is %d",a);
a=5;
printf("\nthe value of a is %d",a);
display();
printf("\nthe value of a is %d",a);
display();
printf("\nthe value of a is %d",a);
getch();
}

void display()
{
static int a;
a++;
printf("\n\nthe value of a is %d",a);
}

// the concept of register storage class.

This class is similar to auto storage class but


variables are stored in register instead of memory.
#include<stdio.h>
#include<conio.h>
void display();
void main()
{
register int a,b;//a and b variables stored in register instead of memory.
clrscr();
printf("\nthe value of a is %d %d",a,b);
getch();
}

Ques) Write individual programs to implement the various storage


classes and exhibit the following properties:
Table of storage class

Storage Key word Initial value Scope lifetime Storage


Class used

Automatic auto Garbage value Local (within a Within a Memory


function) function(local)
External Extern 0 Global Entire program Memory
(global)
Static static 0 Local Entire Memory
program(Global)
Register register Garbage value Local Within a Register
function(Local)

You might also like