हिंदी माध्यम नोट्स
Categories: c++ language in hindi
c++ : scope and linkage , what is scope and linkage in c++ language in hindi , External , internal , Global scope
External , internal , Global scope , c++ : scope and linkage , what is scope and linkage in c++ language in hindi :-
इससे पहले के article मे memory space को discuss किया है | storage class मे data variable के memory access को define किया जाता है | c++ language मे निन्म storage class को मुख्य है :
1. Automatic
जब किसी variable को function definition मे define किया जाता है तब इस variable का storage class automatic होता है | ये variable तब execute होता जब function को execute किया जाता है | variable के लिए allocate memory free हो जाती जब function का execution नहीं होता है | c++ language मे निन्म दो प्रकार के variable होते है :
Static :
जब किसी variable को function के बहार declare किये जाता है पर इस variable को static keyword के साथ declare किया जाता है | तब इस variable को static variable कहते है | इसकी variable की value पुरे प्रोग्राम मे constant रहती है | c++ language मे , तीन प्रकार के static variable होते है |
dynamic :
जब किस variable को new operator से allocate किया जाता है तब इस variable को dynamic variable कहते है | इस variable को free तब किया जाता है जब तक इसकी delete() function को declare नहीं किया जाता है |
Scope And Linkage
scope का मतलब है life time of variable in file |जब किसी variable को function की अनादर use किया जाता है | इस variable को केवल function मे use किया जाता है | लेकिन जब variable को को function के बहार declare किया जाता है तब इस variable को सभी functions मे use किया जा सकता है ||
linkage का मतलब है किसी name को अलग अलग functions मे use कैसे किया जा सकता है | ये दो प्रकार होता है :
External Linkage
जब किसी name को external linkage के साथ use किया जा सकता है तब इस name को अलग अलग files मे use किया जा सकता है |
Internal Linkage
जब किसी name को internal linkage के साथ use किया जाता है तब इस name को केवल एक file के functions को use किया जा सकता है |
c++ मे कई प्रकार के scope को use किया जाता है जैसे
local scope : local scope को केवल एक block मे ही declare किया जाता है | जैसे अगर for()loop मे control variable ‘i’ को केवल फोए loop की body मे ही use किया जा सकता है |इसे block scope भी कहते है | क्योकि इसे block मे ही use किया जा सकता है |
Global scope
global scope का मतलब होता हगे variable की lifetime पुरे प्रोग्राम के समय होता है |
automatic variable का scope local होता है लेकिन static variable का scope global और local दोनों हो सकता है |
name को किसी function के argument मे pass किया जाता है तब इसका scope function prototype scope है | किसी class के member function का scope class scope होता है |जब किसी variable को namespace मे declare किया जाता है तब इस variable का scope namespace होता है |
c++ function का scope class scope और namespace scope दोनों होते है | अतः इसका scope global होता है लेकिन इसका scope local नहीं होता है |
Automatic Storage Duration
function parameter और variables को किसी function के अन्दर declare किया जाता है तब उसका scope आटोमेटिक होता है | इसका scope local होता है लेकिन इसमें linkage नहीं होता है | उदाहरन के लिए ज variable tax को main () function मे use किया जा सकता है या यूजर द्वारा किसी दुसरे function मे equal name का use किया जा सकता है |
जब किसिस प्रोग्राम मे variable को execute किया जाता है तब प्रोग्राम innermost block को allocate करता है | जो की function definition को hold करता है | जब function terminate हो जाता है जब ये block भी free हो जाता है |
#include<iostream.h>
#include<conio.h>
void oil(int a);
using namespace std;
int main()
{
int tax= 234;
int year = 2001;
cout<<“IN main(), tax = “<<tax <<“, &tax : “<<&tax;
cout<<“IN main(), year = “<<year <<“, &year : “<<&year;
oil(tax);
cout<<“IN main(), tax = “<<tax <<“, &tax : “<<&tax;
cout<<“IN main(), year = “<<year <<“, &year : “<<&year;
getch();
}
void oil(int a)
{
int tax = 5;
cout<<“IN oil(), tax = “<<tax <<“, &tax : “<<&tax;
cout<<“IN oil(), a = “<<a <<“, &a : “<<&a;
{
int tax=8;
cout<<“IN block , tax = “<<tax <<“, &tax : “<<&tax;
cout<<“IN block , a = “<<a <<“, &a : “<<&a;
}
इस प्रोग्राम मे variable tax को तीन बार declare किया जाता है | इस function मे variable tax को main() function मे declare किया जाता है | सबसे पहले tax की value print किया जाता है |
इसके बाद tax की value को oil() function मे पास किया जाता है | इसके बाद tax की value को print किया जाता है
oil() मे ,
इस function मे tax को भी declare किया जाता है और इसकी value ‘5’ होती है | इसके बाद tax की value को print किया जाता है |
किसी block मे tax को declare किया जाता है | इसमें tax की value ‘8’ को initial किया जाता है | इसके बाद tax की value को print किया जाता है |
इसका आउटपुट होगा :
IN main(), tax = 234 , &tax : 4032
IN main(), year = 2001 , &tax : 4034
IN main(), tax = 5 , &tax : 4032
IN main(), year = 2001 , &tax : 4034
IN main(), tax = 234 , &tax : 4032
IN main(), year = 2001 , &tax : 4034
IN main(), tax = 8 , &tax : 4036
IN main(), year = 2001 , &tax : 4038
इस article मे , scope को discuss किया जाता है | अब आगे article मे , namespace को discuss करेगे |
Recent Posts
सती रासो किसकी रचना है , sati raso ke rachnakar kaun hai in hindi , सती रासो के लेखक कौन है
सती रासो के लेखक कौन है सती रासो किसकी रचना है , sati raso ke…
13 hours ago
मारवाड़ रा परगना री विगत किसकी रचना है , marwar ra pargana ri vigat ke lekhak kaun the
marwar ra pargana ri vigat ke lekhak kaun the मारवाड़ रा परगना री विगत किसकी…
13 hours ago
राजस्थान के इतिहास के पुरातात्विक स्रोतों की विवेचना कीजिए sources of rajasthan history in hindi
sources of rajasthan history in hindi राजस्थान के इतिहास के पुरातात्विक स्रोतों की विवेचना कीजिए…
2 days ago
गुर्जरात्रा प्रदेश राजस्थान कौनसा है , किसे कहते है ? gurjaratra pradesh in rajasthan in hindi
gurjaratra pradesh in rajasthan in hindi गुर्जरात्रा प्रदेश राजस्थान कौनसा है , किसे कहते है…
2 days ago
Weston Standard Cell in hindi वेस्टन मानक सेल क्या है इससे सेल विभव (वि.वा.बल) का मापन
वेस्टन मानक सेल क्या है इससे सेल विभव (वि.वा.बल) का मापन Weston Standard Cell in…
3 months ago
polity notes pdf in hindi for upsc prelims and mains exam , SSC , RAS political science hindi medium handwritten
get all types and chapters polity notes pdf in hindi for upsc , SSC ,…
3 months ago