JOIN us on
WhatsApp Group Join Now
Telegram Join Join Now

हिंदी माध्यम नोट्स

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 करेगे |
Sbistudy

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…

2 weeks ago

Translation in english grammer in hindi examples Step of Translation (अनुवाद के चरण)

Translation 1. Step of Translation (अनुवाद के चरण) • मूल वाक्य का पता करना और उसकी…

2 weeks ago

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…

2 weeks ago

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…

2 weeks ago

विश्व के महाद्वीप की भौगोलिक विशेषताएँ continents of the world and their countries in hindi features

continents of the world and their countries in hindi features विश्व के महाद्वीप की भौगोलिक…

2 weeks ago

भारत के वन्य जीव राष्ट्रीय उद्यान list in hin hindi IAS UPSC

भारत के वन्य जीव भारत में जलवायु की दृष्टि से काफी विविधता पाई जाती है,…

2 weeks ago
All Rights ReservedView Non-AMP Version
X

Headline

You can control the ways in which we improve and personalize your experience. Please choose whether you wish to allow the following:

Privacy Settings
JOIN us on
WhatsApp Group Join Now
Telegram Join Join Now