I'm working on learning pointers in C++, and was doing fine with int*, double*, etc. but then I tried something that I can't understand. I've attached my code segment, and the comments are the terminal output.
char word[] = "Hello there";
cout << word << endl; //Hello there
cout << *word << endl; //H
cout << &word << endl; //Address
char *wordpt = word;
cout << wordpt << endl; //Hello there
cout << *wordpt << endl; //H
cout << &wordpt << endl; //Address
wordpt = &word[0];
cout << wordpt << endl; //Hello there
cout << *wordpt << endl; //H
cout << &wordpt << endl; //Address
What's going on in these? I don't even understand how the contents of word
(*word
) can be a single index. How is word
stored in memory? And why would wordpt
allow me to give it a value of word
, which isn't an address?