हर एक Variable का एक Memory Address होता है और Memory Address देखने
के लिए Programmer को variable से पहले '&'(address operator) लगाना
पड़ता है |
for eg.
Pointer किसी दूसरे variable का address hold करके रखता है |
हर एक variable का एक address होता है | जब variable declare होता है तभी उसका एक memory location पर वो store होता है |
किसी integer data type variable का address hold करना है तो pointer भी उसी data type का होगा जिस data type का variable हो, मतलब variable int है तो pointer भी int ही होगा, अगर variable char हो तो pointer variable भी char ही होगा | Pointer किसी की value hold करके नहीं रखता, बल्कि सिर्फ उसका address hold करके रखता है और उस address से ही pointer के साथ variable के value को print किया जाता है |
Note : Pointer का address साधारणतः Hexadecimal Numbers होते है, पर कुछ compiler अपना address integer में print करते है | Variable का address print कराने के लिए '%x' या '%u' इन Format Specifiers का इस्तेमाल करते है |

हर variable का address hold करने के लिए जिसका address hold करना है और जिस Pointer variable में hold करना है, तो उन दोनों का data type same होना चाहिए |
for eg.
Dereferencing में pointer में store किये हुए value को access किया जाता है |
for eg.
int a ;
cout<<"Address of a : "<<&a;
Output:
Address of a : 0x69fefc // 0x69fefc is address of variableइसी memory address की मदद से Variable की value को access किया जाता है , इसी को 'Pointers' कहते है |
Pointer किसी दूसरे variable का address hold करके रखता है |
हर एक variable का एक address होता है | जब variable declare होता है तभी उसका एक memory location पर वो store होता है |
For Example
int a = 10;
| Variable_or_Location_name | a | |
| Variable_value | 10 | Location |
| Memory Address | 0x69fefc |
Syntax for Pointer Declaration
data_type *pointer_name;Example for Pointer Declaration
int *ptr1; // integer pointer variable char *ptr2; // character pointer variable float *ptr3; // float pointer variable double *ptr4; // double pointer variable
किसी integer data type variable का address hold करना है तो pointer भी उसी data type का होगा जिस data type का variable हो, मतलब variable int है तो pointer भी int ही होगा, अगर variable char हो तो pointer variable भी char ही होगा | Pointer किसी की value hold करके नहीं रखता, बल्कि सिर्फ उसका address hold करके रखता है और उस address से ही pointer के साथ variable के value को print किया जाता है |
Full Example for Pointer
Source Code :
#include <iostream.h>
using namespace std;
int main(){
int a = 10;
int *ptr; // Integer Pointer Variable
ptr = &a; //address of a stored in ptr
cout<<"Value of a is: "<<a<<endl;
cout<<"Address of a is: "<<ptr;
return 0;
}
Output :
Value of a is: 10 Address of a is: 0x69fef4
Note : Pointer का address साधारणतः Hexadecimal Numbers होते है, पर कुछ compiler अपना address integer में print करते है | Variable का address print कराने के लिए '%x' या '%u' इन Format Specifiers का इस्तेमाल करते है |

Pointers के बारे में और जानते है |
Pointers के दो Methods है |
- Referencing Operator ( & )
- Dereferencing Operator ( * )
1. Referencing Operator
Referencing मतलब किसी दूसरे variable का address hold करके रखना होता है |हर variable का address hold करने के लिए जिसका address hold करना है और जिस Pointer variable में hold करना है, तो उन दोनों का data type same होना चाहिए |
for eg.
int a = 10; int *ptr; ptr = &a; //address of a stored in ptr
2. Dereferencing Operator
Dereferencing में asterisk ( * ) का इस्तेमाल करते पर pointer में इसे Dereferencing Operator भी कहते है |Dereferencing में pointer में store किये हुए value को access किया जाता है |
int a = 10; int *ptr; ptr = &a; int b = *ptr; // ptr means dereferencing cout<<"Value of a : "<<b;Output :
Value of a : 10







No comments: