0
# include <iostream>

int main()
{
    char* cptr{new char};
    std::cout << cptr;
    delete cptr;
}

Output:

debug.

Why? I was expecting an address.

SuperNoob
  • 170
  • 1
  • 10
  • looks like part of your code is missing. show the full code – Raildex May 19 '21 at 09:12
  • @Ralidex That is the full code. – SuperNoob May 19 '21 at 09:15
  • 2
    Does this answer your question? ["cout" and "char address"](https://stackoverflow.com/questions/29188668/cout-and-char-address) – dewaffled May 19 '21 at 09:20
  • C++ iostreams have distinct overloads for printing a `const char *` (which assumes the pointer points at the first character of a nul-terminated string, and prints all characters in that string) and `void *` (which prints the address). Your code is using the first overload since `cptr` has type `char *`. Your code ALSO has undefined behaviour since `cptr` does not actually point at (the first character of) a nul terminated string, but your code does stream output in a manner that ASSUMES it does. – Peter May 19 '21 at 09:23

0 Answers0