accessing elements of 1d array using pointers

Solutions on MaxInterview for accessing elements of 1d array using pointers by the best coders in the world

showing results for - "accessing elements of 1d array using pointers"
Stanislas
06 Jan 2021
1#include<stdio.h>
2
3int main(){
4
5    int arr[] = {1,3,4,5,6,7,8};
6    int *ptr = &arr; //storing address of the first element in array in the ptr
7
8  	//accessing the elements of the array using ptr
9    for(int i=0;i<7;i++)
10        printf("%d ",*(ptr+i));
11  	//here i represents the value to be added to the base address
12    return 0;
13}