Sunday, September 26, 2010

Generating a Pointer to an Array

You can generate a pointer to the first element of an array by simply specifying the
array name, without any index. For example, given
int sample[10];
you can generate a pointer to the first element by using the name sample. Thus, the
following program fragment assigns p the address of the first element of sample:
int *p;
int sample[10];
p = sample;
You can also specify the address of the first element of an array using the &
operator. For example, sample and &sample[0] both produce the same results.
However, in professionally written C/C++ code, you will almost never see
&sample[0].

No comments:

Post a Comment