Hacker News new | ask | show | jobs
by scoutt 2191 days ago
But what is an array anyway? It's just a bunch of (contiguous) memory. That bunch of memory has to start somewhere.

Since an array is just a bunch of memory, by pointing to the beginning of that bunch of memory you are pointing to the entire array.

Here follows a more complicated version:

What the tutorial is not telling you (and now you will hate me for doing things more complicated) is that in C, the alphabet variable is (or can be) treated as a pointer.

If you print the value of alphabet as an number (casting it to unsigned int, for example), you will see that is a position in RAM. That position is the beginning of the array. When you do `alphabet_pointer = alphabet;` you assign to alphabet_pointer the value of alphabet.

If alphabet array starts at address 0x1234, then basically you are doing

    alphabet_pointer = (char*) 0x1234;
Also note that doing `alphabet_pointer = alphabet;` is the same as doing `alphabet_pointer = &alphabet[0];`, being alphabet[0] the first element in the array.