Reputation: 43
Literally, does (char *) 0
mean a pointer to some location that contains a zero? Does the system create such an address with value 0 for each such declaration?
Upvotes: 0
Views: 977
Reputation: 311048
It is null pointer value of type char *
.
From the C++ Standard
A null pointer constant can be converted to a pointer type; the result is the null pointer value of that type
And from the C Standard
3 An integer constant expression with the value 0, or such an expression cast to type void *, is called a null pointer constant.66) If a null pointer constant is converted to a pointer type, the resulting pointer, called a null pointer, is guaranteed to compare unequal to a pointer to any object or function.
4 Conversion of a null pointer to another pointer type yields a null pointer of that type. Any two null pointers shall compare equal.
It is not a pointer that points to a locarion that contains 0. So the system creates nothing. As it is written in the C Standard the null pointer "is guaranteed to compare unequal to a pointer to any object or function". So it is used to determine whether a pointer points to some object or function.
Upvotes: 3
Reputation: 225032
No, it's a cast of 0
to type char *
. That is, a null pointer. A 0
in any pointer context refers to the null pointer constant.
What exactly it points to doesn't matter - dereferencing it would cause undefined behaviour.
For more, check out the C FAQ Part 5: Null Pointers.
Upvotes: 5
Reputation: 1090
its an explicit cast to a null pointer. i believe there is a #define macro for it allowing you to just write NULL
Upvotes: 0