Q:

C Program to print value and address of elements of an array using pointer

0

Write a C Program to print value and address of elements of an array using pointer. Here’s a Simple Program input values into an array and print the value and address on screen using pointer in C Programming Language.

Following C Program ask to the user to enter values that are going to be stored in array. Here we make an intialize an array of 5 elements to be stored in it i.e arr[5].

In this program , we use two for loop : One is to input values in the program to store to an array. And second loop is used to display elements and their particular addresses of an array one by one on the screen.

All Answers

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

Below is the source code for C Program to print value and address of elements of an array using pointer which is successfully compiled and run on Windows System to produce desired output as shown below :


SOURCE CODE : :

/* Program to print the value and address of elements of an array using pointer notation*/


#include<stdio.h>
int main( )
{
        int arr[5];
        int i;
        printf("Enter the array 5 elements : ");
        for(i=0; i<5; i++)
        {
                scanf("%d", &arr[i]);
        }
        printf("\nArray elements with their addresses using pointers : \n");

        for(i=0; i<5; i++)
        {
                printf("Value of arr[%d] = %d\t", i,*(arr+i));
                printf("Address of arr[%d] = %p\n",i,arr+i);
        }

        return 0;
}

OUTPUT : :


Enter the array 5 elements :
6
2
9
1
7

Array elements with their addresses using pointers :

Value of arr[0] = 6     Address of arr[0] = 000000000062FE30
Value of arr[1] = 2     Address of arr[1] = 000000000062FE34
Value of arr[2] = 9     Address of arr[2] = 000000000062FE38
Value of arr[3] = 1     Address of arr[3] = 000000000062FE3C
Value of arr[4] = 7     Address of arr[4] = 000000000062FE40

Above is the source code for C Program to print value and address of elements of an array using pointer which is successfully compiled and run on Windows System.The Output of the program is shown above .

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

total answers (1)

C Pointer Solved Programs – C Programming

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Write a C Program to perform Call By Value and Cal... >>
<< Write a C Program to show an example of pointer to...