If you use &hello
it prints the address of the pointer, not the address of the string. Cast the pointer to a void*
to use the correct overload of operator<<
.
std::cout << "String address = " << static_cast<void*>(hello) << std::endl;
More Related Contents:
- Matrix Printing using Pointers [closed]
- Passing a 2D array to a C++ function
- What exactly is nullptr?
- Why does cout print char arrays differently from other arrays?
- Why aren’t pointers initialized with NULL by default?
- Why is address zero used for the null pointer?
- How many levels of pointers can we have?
- May I take the address of the one-past-the-end element of an array? [duplicate]
- Passing references to pointers in C++
- Can a pointer to base point to an array of derived objects?
- How to get the real and total length of char * (char array)?
- Near and Far pointers
- Check if a pointer points to allocated memory on the heap
- Modifying a char *const string
- Weird Behaviour with const_cast [duplicate]
- Reason why not to have a DELETE macro for C++
- Is the “one-past-the-end” pointer of a non-array type a valid concept in C++?
- What is the difference between std::reference_wrapper and a simple pointer?
- Pointer to array with const qualifier in C & C++
- Is it unspecified behavior to compare pointers to different arrays for equality?
- Are pointer variables just integers with some operators or are they “symbolic”?
- Pointer to array of unspecified size “(*p)[]” illegal in C++ but legal in C
- About Pointers To Functions in function declarations
- How to print member function address in C++
- C++: Why is const_cast evil?
- How to pass a 2d array through pointer in c [duplicate]
- Pointing to a function that is a class member – GLFW setKeycallback
- Is a struct’s address the same as its first member’s address?
- Do pointers to string literals remain valid after a function returns?
- Both asterisk and ampersand in a parameter