sizeof and passing pointer

K

Keith Thompson

Charlie Gordon said:
An array is not a pointer!
An array *has* an address, a pointer *is* an address.

Correct, of course.
When passing an array to a function, only its address is passed, which is
indistinguishible from the value of a pointer to the first element of the
array.

Not quite. When an expression of array type is evaluated it's usually
converted to a pointer to its first element. This is quite different
from the address of the array; the two have the same value (in some
sense), but different types.

For example:

int arr[10];
arr; /* decays to an int*, equivalent to &arr[0] */
&arr; /* this is a pointer to the array, of type int(*)[10] */
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top