Skip to main content
To Get All Information of Sarkari Jobs | Results | Admit Card | And courses ,Internships then CLICK HERE

Storage Class Specifier-:


The type of data refer the size of memory for a variable.These variable also has storage class that reffer the life and scope of variable,within program i.e. within block or function.
There are four types of Storage Class Specifier-:
  1. Automatic Variable
  2. Static Variable
  3. Register Variable
  4. extern variable


Automatic Variable-:
  • The local variable which are declared inside the function are called automatic variable.
  • All the variable declare,without any storage class specifier are assumed to be automatic variable.
  • The scope of the variable is,inside function or block in which they are declared.
  • We can use the same automatic user in different function because after the execution of a function,all automatic C variable are disposed off.
  • The keyword of automatic storage class is"auto".
Example-:
#include<stdio.h>
#include<conio.h>
main()
{ int m=5;
   clrscr();
printf("\n %d ",m);
fun1()
printf("\n Now %d",m);
getch();
}
fun1(int m)
{printf("\n Now %d ",m);
}

Static Variable-:
  • They are same as the automatic variable but it holds the latest value of the variable in the blocks or function in which they are declared.
  • They are of two types-:
  1. Internal Static Variable
  2. External Static Variable
  • A Variable can be declare static by using the keyword static.
  • The default initialization of static variable is 0.
Internal Static Variable-:
  • They are those which are declared inside a function,the scope of internal static variable extends upto the end of function in which they are defined.
  • Therefore internal static variable are similar to automatic variable except that they remain in existence,throughout the remainder of the program.So,internal static variable is used to retain values between function false.
Example-: 
#include<stdio.h>
#include<conio.h>
main()
{int i;      
for(i=0;i<=3;i++)
fun1()
getch();
}
fun1()
{ static int x=1;
   printf("x=%d");
   x++;
}

External Static Variable-: 
  •  An external static variable is declare outside of all the function and is available to all the function in that program.
  • The difference between an external static variable and external variable that external variable is used in the function in which it is define while external variable can be used by other file also.
  • Static variable are created in a place in memory called "Data Segment".
Example -: 
  #include<stdio.h>
  #include<conio.h>
  static int 10;
  main()
{ no.=5;
 printf("\n main no.=%d \n",no);
 fun1();
 fun2();
 printf("After function call no.=%d",no);
getch();
 }
fun1();
{ int x=5;
   no.= no+x;
   printf("\n fun1() no.=%d",no);      
}
fun2()
{int x=5;
no=no+5;
printf("\n fun2() no=%d\n",no);
}

Register Variable-:
  • Register variable are used for storing the value of variable into CPU rrgister.
  • Access time of automatic variable is more than accessing the register variable because the automatic register are store in memory and access time of CPU register take less time than the access time of the variable,which is stored in the memory.
  • So,the variable which are heavily used can be assign on register variable for fast processing.
          Syntax-:
                            register datatype variablename; 
  • Where "register" is keyword,the"&" operator is not used with the register variable.So we can not retrieve the address of the register variable.
External Variable-: 
  • Variable that are both alive and active throughout the entire program are known as external variable and they are also known as global variable.
  • These variable are available to all function in the program.These are declared before the main() and by default it take the initial value zero .
  • The syntax to declare the external variable is as follow-:
                      Syntax-:
                            extern datatype variablename; 



Comments

Post a Comment

Please do not enter any spam link in the comment box.


Download The Book "Let Us C" By Yashavant P.Kanetkar,Click The Below Button

-->Email Subscription

Enter Your Email Address:-

Delivered by FeedBurner

Copyright © 2020 TechProgramiz|All Right Reserved|Made By-: Sudarshan Pandey