Retrieve Data from an Array with the int Type Data using pointers. - C Pointer

C examples for Pointer:Array Pointer

Introduction

Uses a pointer to retrieve the values stored in elements of 1-dimensional int type array.

Demo Code

#include <stdio.h>

int main()//from  w  w w . j a  v  a 2  s  .  com
{
     int marks [] = {1, 2, 3, 4, 5};
     int *ptr;
     
     ptr = &marks[0];
     
     for (int i = 0; i < 5; i++)
        printf("Element no %d, value: %d\n", i+1, *(ptr+i)) ;
     
     printf("Value of array name marks is: %u\n", marks);
     return(0);
}

Related Tutorials