I am learning about pointers in C++. When initializing pointers, for example,
double* pvalue1 = nullptr;//okay
char* pvalue2 = nullptr; //only this says, "0x00000000 <Bad Ptr>" (in the watch window of Visual C++ 2010)
int* pvalue3 = nullptr; //okay
Why does only the
char type pointer give Bad Ptr while other pointer types don't?
I don't care about the pointed-to values at the moment. I am not dereferencing them (that's why there are those errors above). I am just looking at the watch window for those three pointers.
Best How To :
For most pointer types, the Watch window in Visual Studio displays the value of the pointer (the address to which it points), and allows you to access the pointed-to value by expanding the + icon. So for a null pointer to, let's say,
int, it will simply show
0x00000000 or something like that.
char*s are handled differently. Here, the Watch does not show the pointer value at all, but directly interprets the pointed-to data as a
NUL-terminated string and prints that. This of course means that a null
char* does not give meaningful results, hence the
In other words, Watch itself automatically does the dereferencing for
char* pointers (and only for those).