JOIN us on
WhatsApp Group Join Now
Telegram Join Join Now

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

Categories: c++ language in hindi

C++ : Pointer in hindi , what is pointer in c++ language with examples computer programe

what is pointer in c++ language with examples computer programe , C++ : Pointer in hindi :-
इससे पहले के article मे string और structure को discuss किया गया है |अब इस article मे , pointer को discuss करेगे |
isse पहले के article मे , किसी variable के information को हमेशा ट्रैक किया जाता जाता ये information होती है जैसे
1.values कहा store होती है ?
2.value किस तरह की होती है ?
3.value क्या है ?
इस तरह के operation को पूरा करने के लिए simple variable को डेफिन किया जाता है |Declaration statement मे variable का type और name store होता है | जो की कंप्यूटर memory मे एक सप्चे को allocate करता है जिसको इंटरनल ट्रैक किया जाता है |
इसके अलावा C++ मे , इस operation के लिए class को define किया जाता है |इसमें pointer को use किया जाता है |जोकि किसी variable के address को store करता है |किसी variable के address को access करने के लिए address operator का use किया जाता है | अगर variable का नाम ‘a’ है और variable का address ‘&a’ को access करते है |
उदाहरण के लिए :
#include<iostream.h>
#include<conio.h>
void main()
{
using namespace std ;
int a ;
cout<<“Enter value :”<<endl;
cin>>a;
cout<<“value of ‘a’ :”<<a<<endl;
cout<<“Address of ‘a’ : “<< &a << endl;
getcch();
}
इस उदाहरण मे , ‘a’ एक variable है जिसका data type , integer होती है |
cout<<“value of ‘a’ :”<<a ; से variable ‘a’ की value को display किया जाता है |
cout<<“Address of ‘a’ : “<< &a ; से variable ‘a’ के address को display किया जाता है |
इसका आउटपुट होगा :
Enter value : 12
value of ‘a’ : 12
Address of ‘a’ : 0x0065fd40   // यहा पर 0x0065fd40 integer ‘a’ का memory address है |
c++ मे cout statement , memory address को hexadecimal form मे define करता है | किसी डट type के size को define करने के लिए highest value के memory address और lowest value के address को minus करते है | लेकिन दोनों ही variable के type सामान होना चाहिए |
Pointer Declaration
Pointer declaration को समजने के लिए निन्म उदाहरण को discuss किया जाता है :-
#include<iostream.h>
#include<conio.h>
void main()
{
using namespace std ;
int a ;
int *p;
p=&a;
cout<<“Enter value :”<<endl;
cin>>a;
cout<<“value of ‘a’ :”<<a<<endl;
cout<<“Address of ‘a’ : “<< &a << endl;
cout<<“value of ‘p’ :”<<*p<<endl;
cout<<“Address of ‘p’ : “<< &p<< endl;
*p=*p+1;
cout<<“value of ‘p’ :”<<*p<<endl;
getcch();

 

}
इस उदाहरण मे ,pointer को निन्म तरह से declare किया गया है :
int *p;
इसमें ‘p’ एक pointer है जिसका type integer है | अतः ये integer value के address को hold कर सकता है | इसके अलावा किसी दुसरे type की pointer variable को declare करने के लिए :
char *c;
double *d;
char *c;-इसमें ‘c’ एक pointer है जिसका type character है | अतः ये character value के address को hold कर सकता है |
double *d;-इसमें ‘d’ एक pointer है जिसका type double है | अतः ये double value के address को hold कर सकता है |
इस उदाहरण के आउटपुट मे , *p और ‘a’ की value सामान होती है क्योकि p pointer variable है जो की variable ‘a’ की address को hold करता है *p से pointer variable मे store address पर स्थित value को access किया जाता है |
किसी pointer variable मे value को assign करने के लिए *p का use किया जाता है |
इसका आउटपुट होगा :
Enter value : 12
value of ‘a’ : 12
Address of ‘a’ : 0x0065fd40
value of ‘p’ : 12
Address of ‘p’ : 0x0065fd42
value of ‘p’ : 13

इसके अलावा निन्म rules को भी pointer declartion मे consider किया जाता है :-
pointer declaration मे space को use करना थोडा confusion होता है | अतः इसे declare करने के लिए निन्म rules को define किया जाता है :-
1.data  type और * के बीच space हो सकता है |
int *p;
2.* और variable  के बीच space हो सकता है |
int* p;
3.लेकिन अगर हम निन्म syntax को use करते है तब
int* p, a;
यहा पर ‘p’ एक pointer variable है लेकिन ‘a’ एक pointer variable नहीं है |
4.अगर अलग अलग pointer को define करने के लिए अलग अलग declarion को use किया जा सकता है :-
int *p;
char *c;
यह int ये भी define कर रहा ‘p’ की size 4 bytes होगी |
और char define करता है ‘a’ की size 2 bytes होगी |

Pointer Danger
pointer के use बहुत संभाल के करना चाहिए | जब हम किसी pointer variable को declare करते है तब ये ध्यान मे रखना चाहिए :- pointer variable एक memory address को store करने के लिए space को generate करता है इसमें value assign नहीं होती है | उदाहरण के लिए
int *p;
*p=1200;
ये syntax possible नहीं क्योकि pointer को initial ही नहीं किया गया है |1200 भी एक address नहीं है | 1200 , pointer variable मे store address पर assign होगा |

 pointer का उदाहरण :

#include<iostream.h>
#include<conio.h>
void main()
{
using namespace std ;
int a,c ;
int *p;
int *b;
p=&a;
b=&c;
cout<<“Enter value :”<<endl;
cin>>a;
cout<<“Enter value :”<<endl;
cin>>c;
*p=*p+*b;
cout<<“Addition Output :”<<*p<<endl;
getcch();
}
इस उदाहरण मे , addition operation को pointer variable से solve किया गया है |
इस article  मे हमने pointer के basic को discuss किया है |अब आगे के article मे pointer के advance topic को discuss करेगे |
Sbistudy

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