Hacker News new | ask | show | jobs
by stevenvar 2192 days ago
Because most of the time* an array name decays to a pointer to the first element of the array.

So when the array is declared

  char alphabet[10] = {'a', 'b', 'c', 'd', 'e'};
What the alphabet variable "holds" can be seen (this is not exactly true) as a pointer to the array.

Then when you do

alphabet_pointer = alphabet;

You just assign to alphabet_pointer the position in memory of the (first element of) alphabet.

Then alphabet_pointer can be dereferenced to access the content of the array (and not the address of a pointer to the array).

__

* There are some situations where an array name is not considered as a pointer to the array. Notably &array gives you back the address of the array : &array == array.

https://stackoverflow.com/questions/17752978/exceptions-to-a...