Learn C Computer Language Basics | Storage classes in C programming

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);
}


===========================================================================

C Programming Modules

===========================================================================

1 . History Of C programming Language

2 . Data Types

3 . Variables & Constants

4 . Operators & Expressions

5 . Decision Making

6 . Loops

7 . Arrays

8 . Functions

9 . Pointers

10 . String Handling

11 . File Handlings

12 . Storage Classes

13 . Preprocessing

===========================================================================