|
|
|
|
|
by naiveprogrammer
2187 days ago
|
|
And why is that? I am a certified C noob and this really confuses me. Why `alphabet_pointer = alphabet;` points exactly to the first element in the array? Why not the whole array? Why not the last? Can we have a pointer that accepts a whole array? Thanks |
|
So when the array is declared
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...