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

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.

0

u/[deleted] Aug 30 '24

[deleted]

-4

u/[deleted] Aug 30 '24

The adress of the null pointer is 0x0. It's a pointer not an integer but has the value 0.

-5

u/Ghyrt3 Aug 30 '24

No, pointer is an integer. It can be cast to get a dereference. But pointers's is ssize_t in C.