C Tutorials
- What is C?
- History Of C?
- Feature of C?
- How to Install C?
- How to write c program?
- First c program
- Flow of C program
- printf() and scanf() in C
- C Program Structure
- Variables in C
- Data Types in C
- Keywords in C
- C Operators
- Comments in C
- Escape Sequence in C
- Escape Sequence in C
- Constants in C
- C - Storage Classes
- C - Decision Making
- Switch statement in C
- C Loops
- Loop Control Statements
- Type Casting in C
- functions in C
- call by value Or call by reference
- Recursion in C
- Storage Classes in C
- Array
- String
- Pointer
- Pointer And Array
- Pointer with function
- Structure
- Union
- File Handling
- Preprocessor Directives
Important Links
what is Storage Classes?
Storage classes are used to define scope and life time of a variable. There are four storage classes in C programming.
auto :-
The auto keyword is applied to all local variables automatically. It is the default storage class that is why it is known as automatic variable.
#include<stdio.h>
int main(){
int a=10;
auto int b=10;//same like above
printf("%d %d",a,b);
return 0;
}
Output :-
10 10
register :-
The register variable allocates memory in register than RAM. Its size is same of register size. It has a faster access than other variables.
It is recommended to use register variable only for quick access such as in counter.
register int counter=0;
It is recommended to use register variable only for quick access such as in counter.
register int counter=0;
static :-
The static variable is initialized only once and exists till the end of the program. It retains its value between multiple functions call.
The static variable has the default value 0 which is provided by compiler.
The static variable has the default value 0 which is provided by compiler.
#include<stdio.h>
int func(){
static int i=0;//static variable
int j=0;//local variable
i++;
j++;
printf("i= %d and j= %d\n", i, j);
}
int main() {
func();
func();
func();
return 0;
}
output :-
i= 1 and j= 1
i= 2 and j= 1
i= 3 and j= 1
i= 2 and j= 1
i= 3 and j= 1
extern :-
The extern variable is visible to all the programs. It is used if two or more files are sharing same variable or function.
extern int counter=0;