What does a pointer exactly pull to when you make it "null

When you make a pointer point to "null" making the head of the last element of a linked list point to "null", is that is that pointer actually pointing to? some random location in memory?
It isn't pointing to any memory. Or perhaps a reserved piece of memory specifically allocated for a null pointer. Honestly I'm not sure but you can be sure you wont corrupt any data, if you try to access the value of a null pointer it will crash your program.
Last edited on
lachlan but what does it mean to point to nothing? the pointer has to point to something, it can't point to "nothing"? what is "null" exactly? is it a place in memory?

I read somewhere that a pointer pointing to null means it's pointing to a zero-th position in memory that is OS reserved?
I read somewhere that a pointer pointing to null means it's pointing to a zero-th position in memory that is OS reserved?


This is more or less correct.

A pointer just contains an address.

Different addresses can refer to different things (often memory, but maybe also a hardware register or something). Address 0 is set aside for "nothing", so the address goes nowhere, or simply goes somewhere that your program cannot access.
Last edited on
the pointer has to point to something
No, that is the point of a null pointer, it doesn't point anywhere. It's like handing up a blank envelope and asking "Who is this addressed to?", it's not addressed to anyone.
Topic archived. No new replies allowed.