How to access elements of an array using pointers

Code examples

1
0

#include<stdio.h>

int main(){

    int arr[] = {1,3,4,5,6,7,8};
    int *ptr = &arr; //storing address of the first element in array in the ptr

  	//accessing the elements of the array using ptr
    for(int i=0;i<7;i++)
        printf("%d ",*(ptr+i));
  	//here i represents the value to be added to the base address
    return 0;
}

In other languages

This page is in other languages

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................
Балгарскі
..................................................................................................................
Íslensk
..................................................................................................................