हिंदी माध्यम नोट्स
Scope , Visibility और Lifetime of variables in hindi in c language स्कोप , विसिबिलिटी तथा वेरिएबल हिंदी में
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;
Recent Posts
Question Tag Definition in english with examples upsc ssc ias state pcs exames important topic
Question Tag Definition • A question tag is a small question at the end of a…
Translation in english grammer in hindi examples Step of Translation (अनुवाद के चरण)
Translation 1. Step of Translation (अनुवाद के चरण) • मूल वाक्य का पता करना और उसकी…
Report Writing examples in english grammer How to Write Reports explain Exercise
Report Writing • How to Write Reports • Just as no definite rules can be laid down…
Letter writing ,types and their examples in english grammer upsc state pcs class 12 10th
Letter writing • Introduction • Letter writing is an intricate task as it demands meticulous attention, still…
विश्व के महाद्वीप की भौगोलिक विशेषताएँ continents of the world and their countries in hindi features
continents of the world and their countries in hindi features विश्व के महाद्वीप की भौगोलिक…
भारत के वन्य जीव राष्ट्रीय उद्यान list in hin hindi IAS UPSC
भारत के वन्य जीव भारत में जलवायु की दृष्टि से काफी विविधता पाई जाती है,…