I am learning C++ and I was recently learning about references and pointers when I stumbled upon this problem. I have a file called logging.cpp
and it defines a logging function, which takes in a const char* msg
parameter. The function body looks like this:
void Log(const char* msg) {
std::cout << msg << std::endl;
}
iostream is included, I just didnt include it here.
When I use this function in my main file like this:
...
Log("Hello");
...
It prints the whole message. But don't pointers point to a memory address? When I ran this, I expected it to print a memory address. Actually, when I try to dereference it, it only gives me the first letter of the argument ("H").
Why does this happen? I used to think pointers should be dereference in order for the thing they are pointing to to be used.