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

May 21, 2014 at 11:23pm
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?
May 22, 2014 at 1:03am
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 May 22, 2014 at 1:11am
May 22, 2014 at 1:47am
May 22, 2014 at 3:01am
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?
May 22, 2014 at 3:03am
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 May 22, 2014 at 3:04am
May 22, 2014 at 4:03am
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.