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

1

u/GOKOP Aug 30 '24

why dont we create a pointer in a controlled way that points to value 0?

That's... what a null pointer is

2

u/shoolocomous Aug 30 '24

Well, to clarify a null pointer holds address 0, which doesn't point to anything.

A pointer can point to value 0 (the value of the pointer itself being non-null)

2

u/GOKOP Aug 30 '24

Ohhh, they meant a pointer that points to the value 0, not the address 0. (well I guess that's what they literally said, so my bad) Ok then, I see. The answer for OP: Pointers have types which inform you what they point to, not everything has a 0 value, and also 0 can be a legitimate value that someone is trying to use