हिंदी माध्यम नोट्स
Categories: c++ language in hindi
const member function c++ in hindi , what is constant member function in c++ language
what is constant member function in c++ language , const member function c++ in hindi :-
इससे पहले के article मे const के basic को discuss किया तह अब इस article मे const के बारे और कुछ पॉइंट्स को discuss करेगा |
c++ मे , const keyword का use किसी storage को alter करने के लिए किया जाता है |जहा पर global variable का linking external होता है लेकिन const global variable का linking internal होता है | c++ मे जिस पारकर static specifier को use किया जाता है उसी प्रकार global const variable को use किया जाता है |
उदाहरन के लिए
#include<iostream.h>
#include<conio>h>
const int a= 16;
int main() {
cout<<“data : “<<a;
getch();
}
इस उदाहरन मे , a एक global const variable है जिसकी value 16 है ये variable एक static variable की तरह कार्य करता है | इसके value पुरे प्रोग्राम मे constant होता है |
c++ constant variable की value को change करने के लिए simple method होती है | उद्धरण के लिए अगर किसी constant value को header file मे declare किया जाता है | इसे कही जगह use किया जा सकता है | लेकिन इस header file को preprocessor के बाद include किया जाता है | तभी इसे variable को use किया जा सकता है |सभी सौद्र्स file मे global variable को define किया जाता है |
const int a= 10 ;
const char * name = ” parth “;
अगर global variable को रेगुलर variable से external linkage होता है | लेकिन इसमें error होता है | जब किसी global variable को एक file मे define किया जाता है तब केवल इस file मे ही global variable को use किया जाता है | लेकिन किसी दूसरी file मे , इस variable को use करने के लिए extern keyword को use किया जाता है |
इसका उदाहरन है ;
file 1 मे
const int a= 1;
char char * name = parth;
file 2 मे ,
#include<iostream.h>
#include<conio>h>
#include file1 ;
int main() {
cout<<“data : “<<a;
cout<<“name :”<<*name ;
cout<<“Adddress :”<<&name ;
getch();
}
उपर दिए गये उदाहरनो मे ग्लोबल variable को file 2 मे use किया जाता है | इसमें error आता है | क्योकि file 1 और file 2 मे const variable को access नहीं किया जा सकता है |
इसके लिए extern को use किया जाता है |
file 1 मे
extern const int a= 1;
extern char char * name = parth;
file 2 मे ,
#include<iostream.h>
#include<conio>h>
#include file1 ;
int main() {
cout<<“data : “<<a;
cout<<“name :”<<*name ;
cout<<“Adddress :”<<&name ;
getch();
}
इस उदाहरनो मे const variable को external linking को बनाया गया है इसके लिए extern keyword को use किया जाता है | external linking के द्वारा इन variable को file 2 मे use किक्या जा सकता है |
variable मे linking को बजाय जाता है | इसके अलावा function के साथ linking को use किया जा सकता है |
Function linking
c++ मे , एक function के अन्दर दुसरे function को define नहीं किया जा सकता है | in function का scope static storage होता है इन function का life cycle जब तक होता है तब प्रोग्राम की running होगा | जब किसी function को किसी दुसरे function के अन्दर को define किया जाता है तब in function को extern keyword के अथ define किया जाता है | लेकिन यव ऑप्शनल है |
static keyword से function का scope static होता है | इसका linking इंटरनल होता है |
इसका उदाहरन होता है :
#include<iostream.h>
#include<conio>h>
static void add(int , int );
int main() {
int a, b;
cout<<“Enter values :”<<endl;
cin>>a>>b;
add(a,b);
getch();
}
static void add(int e , int f)
{
int c= e+f;
cout<<“Output :”<<c;
}
इस उदहारण मे , function केवल इस file मे use हो सकता है | लेकिन जब किसी function को external के साथ define किया जाता है तब इस function को किसी file मे
c++ मे , const keyword का use किसी memory location को fixed करने के लिए किया जाता है |जहा पर function का linking external होता है लेकिन const global function का linking internal होता है |
उदाहरन के लिए
#include<iostream.h>
#include<conio>h>
const print(char a);
int main() {
cout<<“data : “<<a;
getch();
}
इस उदाहरन मे , print एक global const function है जिसमे line को print किया जाता है ये function एक static function की तरह कार्य करता है | इसके value पुरे प्रोग्राम मे use किया जा सकता है |
c++ constant function की scope को change करने के लिए linking को change किया जाता है | उदाहरन के लिए अगर किसी function को header file मे declare किया जाता है | इसे कही जगह use किया जा सकता है | लेकिन इस header file को pre processor के बाद include किया जाता है | तभी इसे function को use किया जा सकता है |
int add(int , int );
int check( int number );
अगर global function को रेगुलर function से external linkage होता है | लेकिन इसमें error होता है | जब किसी global function को एक file मे define किया जाता है तब केवल इस file मे ही global function को use किया जाता है | लेकिन किसी दूसरी file मे , इस function को use करने के लिए extern keyword को use किया जाता है |
इस article मे , const को discuss किया है अब आगे के article मे c++ के कुछ और advance topic को discuss करेगे |
Recent Posts
मालकाना का युद्ध malkhana ka yudh kab hua tha in hindi
malkhana ka yudh kab hua tha in hindi मालकाना का युद्ध ? मालकाना के युद्ध…
4 weeks ago
कान्हड़देव तथा अलाउद्दीन खिलजी के संबंधों पर प्रकाश डालिए
राणा रतन सिंह चित्तौड़ ( 1302 ई. - 1303 ) राजस्थान के इतिहास में गुहिलवंशी…
4 weeks ago
हम्मीर देव चौहान का इतिहास क्या है ? hammir dev chauhan history in hindi explained
hammir dev chauhan history in hindi explained हम्मीर देव चौहान का इतिहास क्या है ?…
4 weeks ago
तराइन का प्रथम युद्ध कब और किसके बीच हुआ द्वितीय युद्ध Tarain battle in hindi first and second
Tarain battle in hindi first and second तराइन का प्रथम युद्ध कब और किसके बीच…
4 weeks ago
चौहानों की उत्पत्ति कैसे हुई थी ? chahamana dynasty ki utpatti kahan se hui in hindi
chahamana dynasty ki utpatti kahan se hui in hindi चौहानों की उत्पत्ति कैसे हुई थी…
1 month ago
भारत पर पहला तुर्क आक्रमण किसने किया कब हुआ first turk invaders who attacked india in hindi
first turk invaders who attacked india in hindi भारत पर पहला तुर्क आक्रमण किसने किया…
1 month ago