Pointer to array example program in C C++

Pointer to array example program in C C++

C Language में Array और इसके विभिन्न प्रकारो के बारे में और अधिक जानने के लिए देखें— Arrays in C

Pointer to array क्या होता है जानने के लिए देखें—Pointer to array in C

C Language में Pointer to Pointer क्या होता है जानने के लिए देखें— Pointer to pointer in C

Pointer to array example program in C

#include<stdio.h>
int main()
{
    int arr[5]={3,9,1,4,8},i;
    int *ptr;
    ptr=&arr[0];
    for(i=0;i<5;i++)
    {
        printf("Element = %d Address = %u\n",*ptr,ptr);
        ptr++;
    }
    return 0;
}

Pointer to array example program in C++

#include<iostream>
using namespace std;
int main()
{
    int arr[5]={3,9,1,4,8},i;
    int *ptr;
    ptr=&arr[0];
    for(i=0;i<5;i++)
    {
        cout<<"Element = "<<*ptr<<"Address = "<<ptr<<endl;
        ptr++;
    }
    return 0;
}

Output of Pointer to array example program in C C++

Pointer to array example program in C C++

More example programs of array in C C++

  1. Declaration and initialization of array
  2. Input-output in array
  3. Sum and average of array elements
  4. Largest Element in Array
  5. Smallest element in Array
  6. Reverse Elements of Array
  7. Merging two arrays
  8. Searching in array (Linear search)
  9. Sorting in array (Selection sort)
Share it to:

Published by

admin

I am a computer teacher, programmer and web developer