Pointer to Array पॉइंटर टू ऐरे or Pointer of Array पॉइंटरऑफ़ ऐरे or Array Pointer ऐरे पॉइंटर

A pointer variable which stores the base address of an array of the same data type is commonly used to access the elements of that array. It is explained as a pointer to array in introductory C programming.

एक पॉइंटर वेरिएबल जो उसी डाटा टाइप के ऐरे के पहले एलिमेंट का मेमोरी एड्रेस स्टोर करता है, उसे सामान्यतः पॉइंटर टू ऐरे के रूप में समझाया जाता है।

Syntax:

data_type array_name[size], *ptr_name;

ptr_name = array_name;

Example:

int list[5], *p;

p = list;

In the above example, pointer p stores the base address of array list, that is, the address of its first element list[0].

उपरोक्त उदाहरण में पॉइंटर p, ऐरे list का बेस एड्रेस अर्थात उसके पहले एलिमेंट list[0] का मेमोरी एड्रेस स्टोर करता है।

C Program for Pointer to Array

#include <stdio.h>
#include <conio.h>

void main()
{
    int list[5], *p, i;

    clrscr();

    printf("Enter five integer numbers:\n");

    for(i = 0; i < 5; i++)
    {
        scanf("%d", &list[i]);
    }

    p = list;

    printf("Elements of list array are:\n");

    for(i = 0; i < 5; i++)
    {
        printf("%d ", *p++);
    }

    getch();
}

Output:

Enter five integer numbers:
10 20 30 40 50

Elements of list array are:
10 20 30 40 50

Explanation:

In the above program:

  • list[5] is an integer array containing five elements.

  • p = list; stores the base address of array list in pointer p.

  • *p accesses the value of the first array element.

  • *p++ accesses the current element and then increments the pointer to point to the next element.

  • The loop displays all five elements of the array using pointer p.

उपरोक्त प्रोग्राम में:

  • list[5] एक इन्टिजर ऐरे है जिसमें पाँच एलिमेंट स्टोर किए जा सकते हैं।

  • p = list; स्टेटमेंट ऐरे list का बेस एड्रेस पॉइंटर p में स्टोर करता है।

  • *p ऐरे के पहले एलिमेंट की वैल्यू को एक्सेस करता है।

  • *p++ पहले वर्तमान एलिमेंट की वैल्यू एक्सेस करता है और फिर पॉइंटर को अगले एलिमेंट पर ले जाता है।

  • लूप पॉइंटर p की सहायता से ऐरे के सभी पाँच एलिमेंट डिस्प्ले करता है।

Comments

Popular posts from this blog

C Language Topics in Hindi and English

Top High-Paying Tech Skills to Learn in 2025

Complete C Programming Syllabus | Advanced C Roadmap for Students