When I have a code like this :
int* nPtr = 0;
MyClass* myClass = 0;
What compiler really does under the hood. I mean anyway there must be some place in memory to refer.
Does compiler have a special memory block for null pointer to where all they refer ?
Nope. You can’t dereference a NULL pointer and get an object. There’s no object at memory location 0x0 *.
It’s just a convention that we have this one [invalid] pointer value that we can use to identify a pointer as deliberately not pointing anywhere valid.
* – or whatever your implementation decides to use for a 0-pointer