Saturday, April 2, 2016

Storage Classes in C


classes in c programming
Storage classes in c programming language are classified into two main types according to storage area and their behavior, in this c programming tutorial we using this storage classes in many programs:-
1. Automatic storage class
2. Static storage class
3. register
Automatic storage class:
Automatic storage class variable in c programming language will created and destroyed automatically. In Automatic storage class, variables are stores in stack area of data segment or processor register.
Features:
Storage Memory
Scope Local / Block Scope
Life time Exists as long as Control remains in the block 
Static storage class:
Static storage class variables in c language will only exist once and throughout the c program, this storage variable will be always active. Static storage class variables are stores in static area of data-segment.
In a C programming there are four types of scopes are available such as
1. Body scope
2. Function scope
3. Program scope
4. File scope    
Static Storage Class:
The value of static variable linger until the execution of the whole c program. A static variable can be declared using static keyword as shown below:
Syntax:
static int i;
Example:
#include <stdio.h>
void Check();
int main(){
Check();
Check();
Check();
}
void Check(){
static int c=0;
printf("%d\t",c);
c+=10;
}
Output
0 10 20
Register storage class:
The keyword ‘register’ in C programming language is used to define a local variable.
Syntax
register int count;
#include<stdio.h>
#include<math.h>
int main()
{
int num1,num2;
register int sum;
printf("\nEnter the Number 1 : ");
scanf("%d",&num1);
printf("\nEnter the Number 2 : ");
scanf("%d",&num2);
sum = num1 + num2;
printf("\nSum of Numbers : %d",sum);
return(0);
}

0 comments:

Post a Comment