Global Variable in C language | Global Scope | Hindi


इससे पिछले tutorials में हमने scope rules और local variable के बारे में सीखा था यदि आपको scope के बारे में नही पता local variable के बारे में नही पता हैं तो पहले C scope rules और C local variable के बारे में अच्छे से समझले जो की global variable को सीखने में बहुत मदत करेंगे । 
इस tutorial में हम C programming language में global variable या global variable scope के बारे में समझेंगे और सीखेगे वो भी साधारण हिन्दी भाषा में । 

Global variable in C programming | Hindi 

Global variable को gobal variable scope के नाम से भी जाना जाता हैं या आप इसे global scope भी कह सकते हैं । जिसके अंदर variable को access किया जा सकता हैं । 
Variables जो किसी function ब्लॉक के बाहर declare किए जाते हैं और जिन्हें कसी भी फंक्शन के अंदर access किया जा सकता है, global variables कहलाते हें । variables का functions के बाहर declare होना और उन variables को हम functions के अंदर या बाहर कही भी उपयोग कर सकते हैं यानिकी program में कही भी उपयोग कर सकते हैं global scope कहलाता हैं और ऐसे उपयोग होने वाले variables को global variables कहते हैं । 
Global variables , local variables के opposite होते हैं । local scope में variables को function के अंदर declare किया जाता हैं बाहर नही जबकि global scope में variables को function के बाहर declare किया जाता हैं । function के अंदर declare किए जाने variables को local variables और functions के बाहर declare करने वाले variables को global variables कहते हैं । 
जैसे की लोकल variables को उसी function में उपयोग किया जा सकता हैं जिसमे उन variables को declare किया गया हैं जबकि global variables को program में किसी भी function के अंदर या बाहर उपयोग किया जा सकता हैं global variables को functions के बाहर declare किया जाता हैं । 
चलिये C programming में global scope को examples से समझते हैं । 

Examples of global variable in C programming 

#include <stdio.h>
/* global variable declaration */
int a,b,c;
int main ()
{
 /* actual initialization */
 a = 22;
 b = 12;
 c = a - b;
 printf ("value of a = %d, b = %d and c = %d\n", a, b, c);
 return 0;
}

Output – 

value of a = 22, b = 12 and c = 10

उपर दिये गए उदाहरण में हमने a,b,c variables को function से बाहर declare किया और function में उपयोग किया हैं इसलिए यहाँ  पर global scope हैं और इन variables को global variables कहते हैं क्योकि इन variables को function के बाहर declare करने पर भी function में उपयोग किया जा रहा हैं । 
चलिये global variables को एक अन्य उदाहरण से समझते हैं । 

#include <stdio.h>
/* global variable declaration */
int c;
int main ()
{
mul();
}
int mul() 
{
    /* local variable declaration */
    int a,b;
   /* actual initialization */
 a = 22;
 b = 12;
 c = a * b;
 printf ("value of a = %d, b = %d and c = %d\n", a, b, c);
 return 0;  
}

Output – 

value of a = 22, b = 12 and c = 264

इस उदाहरण में हमने एक नया function mul() बनाया हैं उपर दिये गए उदाहरण में आप देख सकते हैं की हमने c variable को global scope में a,b variables को local scope में declare किया हैं । अब हमने mul() function में भी c variable को access किया हैं और main() function में mul() function को call भी कराया हैं इस तरह से देख सकते हैं की global variable को functions से बाहर declare करने पर functions के बाहर या अंदर कही  भी उपयोग किया जा सकता हैं इस तरह के scope को global scope और variable को global variable कहा जाता हैं । 
इस तरह से C programming में gobal variable का उपयोग किया जाता हैं । 


Please Share

Recommended Posts:-