-1

I'm new to C++ and is trying to learn the concept of pointer. I have declared a pointer *pStart and initialised it to equal to 'text'. When I tried to print out the value of the pointer, I was expecting it to equal to the address to which 'text' was stored in, instead, the compiler printed out the string 'hello'. Could someone please explain it to me why this is happening?

char text[] = "hello";

char *pStart = text;

cout << pStart << "  +  " << *pStart <<  "  + " <<  &pStart << endl;
Thor
  • 9,638
  • 15
  • 62
  • 137

1 Answers1

1

This C++ feature is called operator overloading. Depending on the type of the input value certain type of streaming operator is invoked. For the character input look for "insert characters" at the link above or here.

Try this:

std::cout << std::hex << reinterpret_cast<int>(pStart);
Alexander V
  • 8,351
  • 4
  • 38
  • 47