[Solved] C++ char pointer


As others have said, the reason for the empty space is because you asked it to print out str[3], which contains a space character.

Your second question seems to be asking why there’s a difference between printing a char* (it prints the string) and int* (it just prints the address). char* is treated as a special case, it’s assumed to represent a C-style string; it prints all the characters starting at that address until a trailing null byte.

Other types of pointers might not be part of an array, and even if they were there’s no way to know how long the array is, because there’s no standard terminator. Since there’s nothing better to do for them, printing them just prints the address value.

2

solved C++ char pointer