Top Ad unit 728 × 90

What is storage class in c ?

Storage class in c:   

Storage class in c decide the parts of storage to allocated memory for a variable. It is also determines the scop a variable.  Storage class of a variable of c determine the life time it is Globle or local storage class determine variable storage location (Memory or Register). There are basically four Storage classes in c.

1. Automatic Storage class:-   A variable  define with a function or low with auto specifier belong to automatic storage class. Auto means variable are automatically create when needed and delete when they are out of scop. Auto int  a;

Example: 

#include<stdio.h>
#include<conio.h>
void main()
{
auto int  a=10
printf("%d",a);
getch();
}

2. Register storage class:-   Variable belong to register storage class will be accessed frequency therefore they are placed in CPU register not in memory.  They decleared with register specifier and defined in register int a; 

Example:
#include<stdio.h>
#include<conio.h>
void main()
{
register int  a=20;
printf("%d",a)
getch();
}

3. Static Storage class:-   Static variable can be used with in function on file. they decleared with static specifier has different effects local and globule variable. Static int   a;

Example:
 #include<stdio.>
#include<conio.h>
void main()
{
static int  a=1;
printf("%d",a);
a++;
}
void main()
{
fun();
fun();
fun();
getch();
}

4. External Storage class:-   Variable dicleared with a external specifier when there is no storage is allocation to the variable, it is external by default assumed that the variable has already been defined else where in the program. it is comtents globule variable remain in existance  for the entire program.  External int  a;

Example:

#include<stdio.h>
#include<conio.h>
void main()
{
int a;
printf(%d",a);
getch();
}


   

What is storage class in c ? Reviewed by For Learnig on March 07, 2023 Rating: 5

No comments:

If you have any doubts, please tell me know

Contact Form

Name

Email *

Message *

Powered by Blogger.