Q:

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

belongs to collection: C language Pointer Exercises

0

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

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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:

Enter array elements:

21

22

23

24

25

Entered array elements are:

Address         Value

FCB04730        021

FCB04734        022

FCB04738        023

FCB0473C        024

FCB04740        025

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

<< Write C program to concatenate two strings using p...