हिंदी माध्यम नोट्स
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
सती रासो किसकी रचना है , 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