Write C program to read array elements and print the value with the addresses

Introduction

I have used Code::blocks 12 compiler for debugging purpose. But you can use any C programming language compiler as per your availability.

#include <stdio.h>
 
int main()
{
    int arr[10];        //declare integer array
    int *ptr;            //declare an integer pointer
    int  i;
 
    ptr=&arr[0];         //assign base address of array
 
    printf("Enter array elements:\n");
    for(i=0;i < 5; i++){
        scanf("%d",ptr+i);   //reading through pointer
    }
 
    printf("\nEntered array elements are:");
    printf("\nAddress\t\tValue\n");
    for(i=0;i<5;i++){
        printf("%08X\t%03d\n",(ptr+i),*(ptr+i));
    }
 
 
    return 0;
}
 

Result

Write C program to read array elements and print the value with the addresses
Write C program to read array elements and print the value with the addresses

Leave a Comment