Passing a pointer to a character is interpreted as a C string with a NULL termination, since overloading non member std :: ostream <(ostream &) has an overload for a C string with NULL termination (const char *).
template< class CharT, class Traits > basic_ostream<CharT,Traits>& operator<<( basic_ostream<CharT,Traits>& os, const char* s );
As in your case, this is just a symbol, and the subsequent memory cells are garbage, ostream reads the memory until it reaches NULL in the memory stream.
This is definitely undefined behavior, as you will be accessing memory outside of those allocated for your process.
If you really need to pass a pointer to a character and display the address, you can use the formatted operator<< overload of operator<< for void *
basic_ostream& operator<<( const void* value );
To access this, you will need an explicit pointer created from char * to const void *
std::cout << "Value of &char_a is (p_a) :" << static_cast<const void *>(p_a) << std::endl;
source share