What is Pointer in C programming language - Tech S K

Latest

Notes of Computers Technology Information,Latest Tech News, O Level Software Notes,RS CIT notes The notes of all the computer's exams are available here

Recent Posts

Translate

बुधवार, 13 जून 2018

What is Pointer in C programming language


What is Pointer in C programming language

 
What is Pointer in C programming language
What is Pointer in C programming language

C प्रोग्रामिंग लैंग्वेज में Pointer क्या है

इससे पहले हम यह जान चुके हैं कोई भी variable Computer की memory में किस तरह से store होता है. जहाँ store होता है उसका address भी होता है जो यह बताता है कि variable की value memory में कहाँ stored ह. इस address को ही pointer कहते हैं. C/C++ programming language हमें यह सुविधा देती है कि हम किसी variable का address जान सकें(variable का address = वह Memory address/location जहाँ variable की value stored है). C/C++ programming language में किसी भी variable का address जानने के लिए & का use करते हैं. जैसे कि अगर कोई variable int x; है तो x का address &x से मिल जायेगा. जिस तरह से हम int, char, float etc को variable में store कर लेते हैं उसी तरह किसी variable के address को भी. इसके लिए एक नया datatype होता है जो address store करने के काम आता है जिस तरह से integer store करने के लिए int datatype का use होता है. किसी int variable का address store करने के लिए int* datatype का use करते हैं. इसी तरह char variable का address store करने के लिए char* datatype का use करते हैं. नीचे एक छोटा सा example यह show कर रहा है कि किसी variable में दूसरे variable का address कैसे store करते हैं. 
int x = 5;
int* p;
p = &x
यहाँ पहले एक int variable x define किया है, फिर p ऐसा variable declare किया है जो किसी int का address store करता है. फिर p variable में x का address डाल दिया है.(जैसा कि हम जानते हैं कि किसी भी variable का address जानने के लिए & का use करते हैं.) 
Address→01234
Memory→100001111110010100100110000010101100101. . . 
p = &x = 3int x
अब हमारे पास एक variable p है जो कि int* type का है और उसमे x का address stored है - means p को print करेंगे तो x का address print हो जायेगा.(ऊपर दिखाए गए अनुसार यहाँ पर x का address 3 है परन्तु अलग अलह time पर C/C++ program run करने पर address अलग अलग आएगा) यदि हमें यह जानना है कि p में जिस Memory का address लिखा हुआ उस memory पर क्या stored है तो *p का use करते हैं(यहाँ p में उस memory का address है जहाँ x है और उस memory यानि x में 5 stored है इसलिए *p यहाँ पर 5 देगा. इसका एक छोटा सा example देखते हैं. इस example को अपने अनुसार change करके चलाकर देखें और experiement करें. 
#include <stdio.h>

int main() {
  int x = 5;
  int* p = &x;
  printf("x = %d\n",x);
  printf("address of x = %d\n", p);
  printf("value at location p = %d\n", *p);

  scanf("%d", &x);
  return 0;
}
 अगले topic में Hindi में C tutorial को आगे बढ़ाते हुए pointer के use देखेंगे.

कोई टिप्पणी नहीं:

एक टिप्पणी भेजें

Friends, if you like this post then please share it on Facebook! Please tell through the comments that these posts will welcome you as well as your suggestions.