When in C++ I declare a null pointer to be int* p=0, does that mean the zero is some special constant of integer pointer type, or does it mean that p is pointing to address 0x0?
Of course for that 0x0 would have to be an special address to which C++ never touches during allocation of variables/arrays.
When in C++ I declare a null pointer to be int* p=0 , does
Share
The C++ standard defines that the integer constant 0 converts to a null pointer. This does not mean that null pointers point to address 0x0. It just means that the text ‘0’ turns into a null pointer when converted to a pointer.
Of course, making null pointers have a representation other than
0x0is rather complicated, so most compilers just let0x0be the null pointer address and make sure nothing is ever allocated at zero.Note that using this zero-conversion is considered bad style. Use
NULL(which is a preprocessor macro defined as0,0L, or some other zero integral constant), or, if your compiler is new enough to support it,nullptr.