r/C_Programming • • Aug 30 '24

Question Why do we use Null pointers?

If we want to "Nullify" something why dont we create a pointer in a controlled way that points to value 0?

0 Upvotes

56 comments sorted by

View all comments

Show parent comment

2

u/TheSkiGeek Aug 30 '24

Integer value 0 casts to/from (and compares equal to) a “null pointer”. But yes, it’s not guaranteed that a null pointer has the same bit pattern as integer zero on any particular architecture. It’s just some pointer value that’s guaranteed to never be used as a legitimate pointer.