Since both are pointing to the same object, if either obj or d_header is changed, the change will be reflected in the other.
That is incorrect. If the contents of what they point to is changed, that change can be seen through either pointer but if one of them is changed so that it points to something different, the other will still point to the previous object.
Simple example:
int i = 10;
int j = 20;
int* ptr1 = &i;
int* ptr2 = ptr1;
At this point, both the pointers point to the same object, i. Value of i can be changed by:
Directly by assigning a value to i.
i = 15;
Indirectly by assigning a value to where ptr1 points to.
*ptr1 = 15;
Indirectly by assigning a value to where ptr2 points to.
*ptr2 = 15;
However, you can change where ptr1 points to by using:
ptr1 = &j;
Now, ptr1 points to j but ptr2 still points to i.
Any changes made to i will be visible through ptr2 but not ptr1.
Any changes made to j will be visible through ptr1 but not ptr2.
Isn't obj also pointing to null, since both object were pointing to the same object?
The answer should be clear now. obj continues to point to what d_header used to point to. It is not NULL.
So what is the deal of returning a Null pointer?
The function does not necessarily return a NULL pointer. The function returns whatever d_header used to point to before it was changed to be nullptr. It could be a NULL pointer if d_header used to be NULL before the call to the function.
is nullptr in this case would be the same as delete?
No, it is not. There are two different operations. Assigning a pointer to nullptr does not automatically mean that delete gets called on the pointer. If you need to deallocate memory that a pointer points to, you'll have to call to call delete explicitly.
nullptrdoesn't mean you're pointing to null, but rather that it value is a null pointer (in other words an invalid pointer or empty pointer - a pointer to nowhere in some sense). This should give a glance at an answer to your first question. A glance to your second: no.void *x = NULL; int *y = &x;ypoints toNULL, butyis not anullpointer.