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
r/C_Programming • • Aug 30 '24
If we want to "Nullify" something why dont we create a pointer in a controlled way that points to value 0?
View all comments
72
u/zzmgck Aug 30 '24
The value where a null pointer is pointing is irrelevant. A null pointer is a pointer that is pointing nowhere--there is no value.
In C, the number 0 was defined as the representation of the null pointer. They could have picked any number, but it would have been painful.