Solution for Exercise 18-7

ex1807

#include <stdio.h>

int main()
{
    char hello[] = "Hello!";
    int i = 0;

    while(hello[i])
    {
        printf("%c at %p\n",hello[i],&hello[i]);
        i++;
    }
    return(0);
}

Notes

* The format &hello[x] displays the address of element x in an array.

* The & operator isn't necessary when referring to an array as a whole. That's because an array name by itself, such as hello, represents the array's base address in memory. In that case, &hello is redundant. It may not cause any warnings, but it's unnecessary and potentially confusing. This topic is discussed in Chapter 19