C programming storage class
In this tutorials, you will learn:-
Storage Classes:-
Storage class is define the scope (visibility) life time of variable or function with in the program.
C programming has four types of storage classes:-
1 Auto (all local values)
2 Extern (all global variable)
3 Static (local variables)
4 Register (fast accessing memory)
Auto :- Auto is the deafult storage class for all local variable . The scope of an auto variables local and they initialize some garbage value for a local variable if data isn't given.
E.g:- #includde<stdio.h>
#include<conio.h>
void mian()
{
auto int x;
printf("value is %d",x);
getch();
}
OUTPUT:
value is 52725872 (GARBAGE VALUE)
2 Extern:- Extern is a storage class for all global variables. The scope of extern variables is the throughout the program nd extern variable always define outside the main function and we can use as global variable.
For e.g:-0
#include<stdio.h>
#include<conio.h>
extern int g=10;
void main()
{
printf("%d",g);
getch();
}
3 Statics :- Static variable is local variable but its lies as global variable . A static variable can be initialize only at once a static variable initialize by zero automatically when data is not given.
For e.g:- #include<stdio.h>
#include<conio.h>
void main()
{
static int x;
printf("value is =%d",x);
getch();
OUTPUT
value is =0
4 Register :- Register is used to define local variable that should be store in a register memory instead of RAM memory. Generally, it is done for fast accessing of variable because the speed of register is high the RAM . We can define variable on register only for local variable don't have any address.
For e.g:-
#include<stdio.h>
#include<conio.h>
void main()
{
register int c=10;
printf("value is =%d",c);
getch();
}
OUTPUT :-
value is= 10
difference between all four variable:-
classes
dcgdljcdi
Classes |
Storage
|
Value
|
Scope
|
Auto
|
memory
|
Garbage value
|
local variable
|
extern
|
memory |
Zero
|
global variable
|
static
|
memory
|
Zero
|
local variable
|
register
|
CPU memory
|
Garbage value
|
local variable
|
All four variable in one program..........
include<stdio.h>
#include<conio.h>
extern int y=10;
void main()
{
auto int x=1;
static int u=1;
register int s-2;
x= 1; _________________________ This is possible .
x++;
u=1; __________________________ This i snot possible
u ++;
s=2; ___________________________ This is possible
s++;
c programming language
c programming for prime number
c programming basics
c programming structure
c programming tutorial
c programming array
c programming questions for interview
c programming pdf
for c programming example
c programming examples
c programming questions
c programming interview questions
c programming hello world
what c programming
c programming online compiler
c programming functions
c programming string
c programming online
c programming com…
c programming language
c programming for prime number
c programming basics
c programming structure
c programming tutorial
c programming questions for interview
c programming pdf
for c programming example
c programming examples
c programming questions
c programming interview questions
c programming hello world
what c programming
c programming online compiler
c programming functions
c programming string
c programming online
c programming compiler
c programming in vs code
how learn c programming
c programming software
c programming reverse number
c programming for loop
c programming practice
c programming for beginners
c programming examples with output
c programming recursion
0 comments:
Post a Comment
If you have any doubt, please let me know