I've recently been reading tutorials on arrays and their aquaintance with memory addresses. So, I completely understand how an array's name, when defined, is a constant pointer to its first element's address.
My problem, however, lies with characters, and how they are basically arrays except with a null terminator for the last index. What I've come to undestand, is that, when defining a character variable, each 'character' has a memory address it is associated with.
For example:
|
char name[] = {"Hello"}; // | 'H' | 'e' | 'l' | 'l' | 'o' | '/0' |
|
An address holds the value of 'H'.
An address holds the value of 'e'.
An address holds the value of 'l' and so on.
I have come to believe this is false, however. Mainly from a simple std::cout command.
1 2
|
std::cout << &name << std::endl; // attempt 1
std::cout << &name[0] << std::endl; // attempt 2
|
The first attempt, as I assumed, should print the address of the first element.
The second attempt, as I assumed, did not. I figured,
&names[0] would print the address of the first element, which should have been the same as
&names.
So, this brings me to my question, are characters formed of constant addresses, or are the address of individual characters not reachable? I'm heavily confused as to what might be happening concerning this issue.
Thanks for reading, and I hope someone can shed some light upon me.