Scope , Visibility और Lifetime of variables in hindi in c language स्कोप , विसिबिलिटी तथा वेरिएबल हिंदी में

स्कोप , विसिबिलिटी तथा वेरिएबल हिंदी में Scope , Visibility और Lifetime of variables in hindi in c language :-
C language मे Scope , Visibility और Lifetime of variables के आधार पर , variable को char प्रकार मे बाटा गया है |
1.Automatic Variable
2.External variable
3.Static Variable
4.Register Variable
यहाँ पर
Scope : Scope ये बताता है की प्रोग्रम का कोनसा पार्ट मे variable को use किया जा सकता है |
Longevity :Longevity का मतलब है variable का lifetime period जिसमे variable data को contain करेगा |
Visibility : Visibility का मतलब है की variable को memory से कब तक एक्सेस कर सकते है |Declaration के आधार ,variable को दो प्रकार मे बाटा गया है :-
Internal (local) variable:
जब variable को main() function मे declare किया जाता है उसे Internal (local) variable कहते है |और इस variable को केवल main() function मे use किया जाता है |
External (Global ) variable:
जब variable को main() function के बाहर declare किया जाता है उसे External (Global ) variable कहते है |और इस variable को केवल main() function के साथ use define function मे भी use किया जा सकता  है |

1.Automatic Variable
Automatic Variable को किसी function मे declare किया जाता है |
जा कोई function को call किया जाता है तब  ये variable memory मे assign होता है |और जब function exit होता है तब variable आटोमेटिक destroyed हो जाता है |
इस तरह Automatic Variable को internal और local variable होता है |
जब किसी variable के storage class को declare नहीं किया जाता है तब उसका default storage class automatic होती है |
इस storage class की सबसे बड़ी property होती है की इसकी value किसी दुसरे function के प्रोसेस से change नहीं हो सकता है |
इसका उदहारण है :

#include<stdio.h>
#include<conio.h>
void div( );
void main()
{
float d;
d=div();
printf(“%f”,d);
getch();
}
void div()
{
int a,b;
printf(“data”);
scanf(“%d %d”,&a,&b);
return(a/b);
}

इस उदहारण मे , दो variable a और b एक automatic variable होता है |जिसका अस्तिव केवल div() function के execution time तक ही होता है |

External Variables :
वे variable जिसका अस्तिव पुरे प्रोग्राम के समय होता है उसे external variable कहते है |इस variable को global variable कहते है |इस variable को function declaration  से पहले declare  किया जाता है |
इसका उदहारण है :-
#include<stdio.h>
#include<conio.h>
void div( );
float d;
void main()
{
div();
getch();
}
void div()
{
int a,b;
printf(“data”);
scanf(“%d %d”,&a,&b);
d=(a/b);
printf(“%f”,d);
}

इस उदहारण मे  d एक global variable है जिसका type float है और इसे किसी function मे use किया जा सकता है |

Problem with External Variables :
1. अगर किसी global variable को function arguments मे pass किया जाता है तब called function मे हुए changes का effect global variable पर होता है |global variable as function argument re usability का शिकार हो जाता है |
2. global variable का अस्तिव उसके declartion से प्रोग्राम के end तक होता है अतः नीचे दिए गया प्रोग्रम मे , variable ‘d’  को main() function मे use नहीं कर सकते है |
#include<stdio.h>
#include<conio.h>
void div( );
void main()
{
int g,h;
div();
g=d+h;
getch();
}
int d;
void div()
{
int a,b;
printf(“data”);
scanf(“%d %d”,&a,&b);
d=(a/b);
printf(“%f”,d);
}

इस प्रॉब्लम को solve करने के लिए ,variable का type extern होता है |extern data type का मतलब है variable पुरे प्रोग्राम मे कही पर भी declare किया जा सकता है |लेकिन variable के लिए कोई memory space allocate नहीं होता है |

Static variable :
static variable वे variable होते है जिसका अस्तिव पूरे प्रोग्राम के execution के समय होती है | इसका syntax होता है |

static variable type variable name ;

static variable दो प्रकार के होते है :-
1.Internal Static variable :
ये variable को function मे declare किया जाता है |इस वरिअब्ल्ले का अस्तिव पुरे function के समय होता है|लेकिन इस variable को केवल एक बार initail कर सकते है |इसका उदहारण है |
#include<conio.h>
#inclue<stdio.h>
void count();
void main()
{
for(int j=0;j<10;j++)
{
count();
}
getch();
}
void count()
{
static int i=1;
printf(“%d”,i);
i++;
}
इस उदाहरण मे i एक variable है जिसकी storage class static है |इसलिए
जब j=0 होगा तब function count() call होगा और i=1 print होगा |
जब j=1होगा तब function count() फिर से call होगा और i की increament value 2 print होगी  |
जब j=1होगा तब function count() फिर से call होगा और i की increament value 3 print होगी  |
यही प्रोसेस tab तक चलेगी जब तक j की value 10 नहीं हो जाती है |

अगर i की storage class आटोमेटिक होती तो i की value हर loop के लिए initial होगा आउटपुट होता है 1 1 1 1 1  1 1 1 1 1

लेकिन आउटपुट होगा :
1 2 3 4 5 6 7 8 9 10

External Static Variable :
जब किसी static variable को function के बहार declare किया जाता है तब इसका storage class External Static होगा |इसे किसी भी function मे use किया जा सकता है |

Register variable:
जब किसी variable को memory मे नहीं register मे store किया जाता है तब इसका storage class register होगा |इसमें store data का execution time बहुत कम होता है |इस storage class मे loop control variable को store किया जाता है तभी loop का execution time का कम होगा |
इसका syntax है :-
register variable type variable_name;