Currently, I'm trying to understand why I have to use:
std::cout << "&str1:" << &str1 << std::endl;
To get the memory address of:
const char * str1 = "Good Morning";
I expected that:
std::cout << "str1:" << str1 << std::endl;
would do so.
Here is an example:
void charPointerExamples() {
const int * myInt = new int(1);
const char * str1 = "Good Morning";
const char * str2 = str1;
std::cout << "myInt:" << myInt << std::endl;
std::cout << "&str1:" << &str1 << std::endl;
std::cout << "&str2:" << &str2 << std::endl;
std::cout << "str1:" << str1 << std::endl;
std::cout << "str2:" << str2 << std::endl;
std::cout << "*str1:" << *str1 << std::endl;
std::cout << "*str2:" << *str2 << std::endl;
delete myInt;
}
The output itself:
myInt:0081D450
&str1:003CFD20
&str2:003CFD14
str1:Good Morning
str2:Good Morning
*str1:G
*str2:G