JOIN us on
WhatsApp Group Join Now
Telegram Join Join Now

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

Categories: c++ language in hindi

C++ : SCOPE in hindi , what is scope in c++ language

what is scope in c++ language , C++ : SCOPE in hindi :-

इससे पहले के article मे function के type , structure , default parameter और return statement को discuss किया गया है | function के आधार variable को दो भागो मे divind किया गया है |

C++ language मे  किसी variable को दो feture होता है :-

1.type : ये data variable के type को define करता है |

2.Storage class : ये data variable के visiablity , scope और usage को define करता है | storage class से variable की lifetime और scope को define करता है | lifetime का मतलब है variable की time period जब तक ये active होता है | और scope का मतलब होता है variable की activeness प्रोग्राम मे जब तक active रहता है |

c++ मे data type int , char , float और double आदि होते है | जिसे हम पहले discuss कर चुके है | अब इस article मे storage class को discuss करेगे |

c++ मे निन्म मुख्य storage class होती है :-

1.local variable

जब किसी variable को function के अन्दर declare किया जाता है | उस variable को local variable कहते है इसमें variable को {} मे लिखा जाता है | अतः scope केवल function की body मे ही होता है | अथार्त variable का activeness केवल function की body मे ही होता है | जब प्रोग्राम / function को terminate किया जाता है तब local variable का activeness भी destroyed हो जाती है |

इसका उदाहरन होता है :

#include<iostream.h>

#include<conio.h>

#include<math.h>

void main()

{

int a,b    ;

cout<<“Enter value 1  : “;

cin>>a;

cout<<“Enter value2 : “;

cin>>b;

int output = fmod(a,b);

cout<<” remainder output of v2/v1:”<<output<<endl

}

getch();

}

इसके उदाहरन मे , यूजर द्वारा दो value को input किया जाता है | इन value को  a और b  मे assign किया जाता है | और इस  int output = fmod(a,b); इस statement से  first remainder expression  की  value को calculate किया जाता है | यहा पर variable ‘a’ और ‘b’ दोनों local variable है क्योकि इन्हें main() function मे declare किया गया है | in variable को main() function के बहार use नहीं कर सकता है |

इसका आउटपुट होगा :

Enter value 1  : 100

Enter value 2  : 1000

remainder output of v1 : 100

1.Global variable

जब किसी variable को function के बहार declare किया जाता है | उस variable को global variable कहते है इसमें variable को {} के बहार  लिखा जाता है | अतः scope पुरे function की body के साथ दुसरे main() मे ही होता है | अथार्त variable का activeness function की body और main() मे ही होता है | जब प्रोग्राम / function को terminate किया जाता है तब local variable का activeness भी destroyed नहीं  होता  है |

इसका उदाहरन होता है :

#include<iostream.h>

#include<conio.h>

#include<math.h>

int a,b ;

void sub(int , int );

void main()

{

cout<<“Enter value 1  : “;

cin>>a;

cout<<“Enter value2 : “;

cin>>b;

int output = fmod(a,b);

cout<<” remainder output of a/b:”<<output<<endl

}

getch();

}

void add(int  ,int )

{

cout<<“Enter value 1  : “;

cin>>a;

cout<<“Enter value2 : “;

cin>>b;

int c= a+b;

cout<<” addition  output of a+b :”<<c<<endl

}

इसके उदाहरन मे , यूजर द्वारा दो value को input किया जाता है | इन value को  a और b  मे assign किया जाता है | और इस  int output = fmod(a,b); इस statement से  first remainder expression  की  value को calculate किया जाता है | यहा पर variable ‘a’ और ‘b’ दोनों global variable है क्योकि इन्हें main() function के बहार declare किया गया है | इन  variables को main() function और add() function मे use किया गया है  |

इसका आउटपुट होगा :

Enter value 1  : 100

Enter value 2  : 10

remainder output of a/b : 10

Enter value 1  : 100

Enter value 2  : 1000

addition output of a+b : 1100

Static variable

static variable एसे variable को कहते है जिसका scope local variable के तरह होता है लेकिन इसकी value पुरे प्रोग्राम मे constant रहता है | इसका मतलब है की इस variable की activeness केवल प्रोग्राम / function तक रहती है | और अगर एक बार static variable को initial किया जा सकता है | उसके बाद इसकी value को change नहीं कर सकता है | इस variable को declare करने के लिए static keyword को use किया जाता है |

#include<iostream.h>

#include<conio.h>

#include<math.h>

void sub(int , int );

void main()

{

static int a,b ;

cout<<“Enter value 1  : “;

cin>>a;

cout<<“Enter value2 : “;

cin>>b;

int output = fmod(a,b);

int output2 = add(a,b);

cout<<” remainder output of a/b:”<<output<<endl;

cout<<” addition  output of a+b :”<<c<<endl;

}

getch();

}

void add(int e  ,int f )

{

int c= e + f ;

return c;

}

इसके उदाहरन मे , यूजर द्वारा दो  static value को input किया जाता है | इन value को  a और b  मे assign किया जाता है | और इस  int output = fmod(a,b); इस statement से  first remainder expression  की  value को calculate किया जाता है | और इस  int output = add(a,b); इस statement से  addition  को calculate किया जाता है  यहा पर variable ‘a’ और ‘b’ दोनों static variable है क्योकि  इन्हें  value को एक बार initail किया जा सकता है |

इसका आउटपुट होगा :

Enter value 1  : 100

Enter value 2  : 10

remainder output of a/b : 10

addition  output of a+b : 1100

Register variable

Register variable ये variable होता है जिसे computer memory मे register मे store किया जाता है |इसे declare करने के लिए register keyword को use किया जाता है | ये variable नोरमल variable की तरह होते है लेकिन इन  variable नोरमल variable से faster access किया जा सकता है | c++11 मे register variable को declare नहीं किया जाता है | क्योकि register keyword को c++11 मे allow नहीं  कर   सकते    है |

Thread Local Storage

Thread Local Storage ये वो class होती है जिसमे variable के एक उदाहरन को प्रोग्राम मे declare किया जाता है इसके लिए Thread_local keyword को use किया जा सकता है |

इस article मे storage class को अच्छी तरह से discuss किया गया है | अब आगे के article मे function recursion को discuss करेगे |

Sbistudy

Recent Posts

सती रासो किसकी रचना है , sati raso ke rachnakar kaun hai in hindi , सती रासो के लेखक कौन है

सती रासो के लेखक कौन है सती रासो किसकी रचना है , sati raso ke…

16 hours ago

मारवाड़ रा परगना री विगत किसकी रचना है , marwar ra pargana ri vigat ke lekhak kaun the

marwar ra pargana ri vigat ke lekhak kaun the मारवाड़ रा परगना री विगत किसकी…

16 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
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