Solution for Exercise 19-5

ex1905

#include <stdio.h>

int main()
{
    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);
}

Notes

* To display each element's address, you need to re-initialize the value of pn, which is done at Line 18 above.

* You also must remember to increment variable pn in the for loop, as is done at Line 25.