Hi,
A pointer variable is a variable that stores an address in memory. An address in memory is a series of numbers. Normally, if you cout<< a pointer variable, you can see the address displayed in hexadecimal format. Try this:
Code:
int nums[] = {1, 2, 3};
cout<<nums<<endl;
However, if you try that on a pointer to a char array, you won't get an address. cout<< is programmed differently to handle pointers to char arrays. Instead of outputting the contents of the pointer variable, i.e. the address, cout<< goes to the address in memory contained in the pointer variable and tries to output all the values in the array located there. It looks for a '\0' to know when to stop. If there isn't a '\0' at the end of the char array, then cout<< will overrun the end of the array and output a bunch of junk. The main point is, in an attempt to understand what a pointer variable really contains, using cout<< on char arrays isn't insightful.
The reason the code outputs 4 is because sizeof() returns the size of the pointer variable. A pointer variable contains an address, and an address takes up 4 bytes of memory. The reason the code outputs 1 is because the value at that location in memory, which is obtained by dereferencing the pointer, is a char, and by definition sizeof() returns 1 for a char type.