Is a pointer pointing to 0x0000 the same as a pointer set to NULL? If NULL value is defined in the C language, then what location does it physically translate to? Is it the same as 0x0000. Where can I find more details about these concepts?
- Anybody can ask a question
- Anybody can answer
- The best answers are voted up and rise to the top
A point that most of the answers here are not addressing, at least not explicitly, is that a null pointer is a value that exists during execution, and a null pointer constant is a syntactic construct that exists in C source code.
A null pointer constant, as Karlson's answer correctly states, is either an integer constant expression with the value 0 (a simple
So a literal
This implies, among other things, that
I don't know why this question isn't considered a duplicate of this one, or how it's topical here.
Every platform out there is free to define NULL as it pleases.
According to the C Standard, if you assign zero to a pointer it will be converted to a NULL value (for that platform.) However, if you take a NULL pointer and cast it to int, there are no guarantees that you will get zero on every platform out there. The fact however is that on most platforms it will be zero.
Information about that stuff you can find in The C Language Specification. One source, the trustworthiness of which I cannot vouch for, is this: http://www.winapi.co.kr/pds/doc/ISO-C-FDIS.1999-04.pdf
It is defined in the C language because there is no one unvarying machine address that it equates to. If it did, we wouldn't need an abstraction from it! Even though on most platforms, NULL might eventually be implemented as 0 of some type or other, it's simply wrong to assume that this is universally so, if you care about portability at all.
According to C Standard Document section
So far I have not seen a compiler that has broken away from this.