C - Write program to display address of each element in the array along with its value

Requirements

Write program to display address of each element in the array along with its value

Hint

You should see that each address is separated by 4 bytes.

Demo

#include <stdio.h>

int main()//from   w  ww .j  av a2 s.co  m
{
    int numbers[10];
    int x;
    int *pn;

    pn = numbers;       /* initialize pointer */

/* Fill array */
    for(x=0;x<10;x++)
    {
        *pn=x+1;
        pn++;
    }

    pn = numbers;

/* Display array */
    for(x=0;x<10;x++)
    {
        printf("numbers[%d] = %d, address %p\n", x+1,numbers[x],pn);
        pn++;
    }

    return(0);
}

Result

Related Exercise