Storage Class Specifier: IN C

Auto Example:

#include<stdio.h>
void main()
{
    Display();
    Display();
    Display();
}

void Display(){
auto int x=1;
x=x+5;
printf("%d\n",x);
}

Output:
6
6
6
Static Example:

#include<stdio.h>
void main()
{
    Display();
    Display();
    Display();
}

void Display(){
static int x=1;
x=x+5;
printf("%d\n",x);
}

Output:
6
11
16
Register:

#include<stdio.h>
int main(){
register int a,b,c;
a=10;
b=20;
c=a+b;
printf("%d",c);

return 0;
}

It will take short time as calculation happen in registers.
extern example:

#include<stdio.h>
void test(){
    extern int gvar;
    printf("gvar=%d",gvar);
    gvar=20;
}
int gvar;
int main(){

//extern int gvar;
printf("gvar=%d\n",gvar);
gvar=10;
test();
printf("gvar = %d",gvar);
return 0;
}

 

It would be a great help, if you support by sharing :)
Author: zakilive

Leave a Reply

Your email address will not be published. Required fields are marked *