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;
Related Contents:
- What is array to pointer decay?
- How do I use arrays in C++?
- When should static_cast, dynamic_cast, const_cast and reinterpret_cast be used?
- Is it a good idea to typedef pointers?
- Passing a 2D array to a C++ function
- Is segmentation fault actual undefined behavior when we refer to a non-static data-member
- Pointer to class data member “::*”
- Function does not change passed pointer C++
- Return array in a function
- Why does the use of ‘new’ cause memory leaks?
- C/C++: Pointer Arithmetic
- May I treat a 2D array as a contiguous 1D array?
- Declaring pointers; asterisk on the left or right of the space between the type and name? [duplicate]
- What is uintptr_t data type
- NULL vs nullptr (Why was it replaced?) [duplicate]
- C++ pass an array by reference
- Why are references not reseatable in C++
- Uses for multiple levels of pointer dereferences?
- What is the ‘this’ pointer?
- What makes more sense – char* string or char *string? [duplicate]
- Pointers, smart pointers or shared pointers? [duplicate]
- C/C++ int[] vs int* (pointers vs. array notation). What is the difference?
- Conversion of pointer-to-pointer between derived and base classes?
- Checking if this is null
- Pointers in c++ after delete
- How are iterators and pointers related?
- Why does streaming a char pointer to cout not print an address?
- What is the purpose of allocating a specific amount of memory for arrays in C++?
- Can I use if (pointer) instead of if (pointer != NULL)?
- Passing references to pointers in C++
- C++ Is it possible to determine whether a pointer points to a valid object?
- Can a pointer to base point to an array of derived objects?
- Why are NULL pointers defined differently in C and C++?
- What happens to the pointer itself after delete? [duplicate]
- What is the use of intptr_t?
- Why not use pointers for everything in C++?
- Create new C++ object at specific memory address?
- C++: Is it safe to cast pointer to int and later back to pointer again?
- Store an int in a char array?
- error: invalid initialization of non-const reference of type ‘int&’ from an rvalue of type ‘int’
- C++ typedef interpretation of const pointers
- Is it unspecified behavior to compare pointers to different arrays for equality?
- Modifying a char *const string
- Why are `&array` and `array` pointing to the same address?
- Difference between const. pointer and reference?
- Convert C++ function pointer to c function pointer
- Are non dereferenced iterators past the “one past-the-end” iterator of an array undefined behavior?
- What does ‘return *this’ mean in C++?
- Polymorphism & Pointers to arrays [duplicate]
- Using a C string gives a warning: “Address of stack memory associated with local variable returned”