How to assign a value to a pointer that points to NULL
c++
Solution
Pointers refer to a location in memory (RAM). When you have a `null pointer` it is pointing to null, meaning that it isn't pointing to location in memory. As long as a pointer is null it can't be used to store any information, as there is no memory backing it up.
To use a null pointer you must first allocate memory and then have the pointer point to that newly allocated memory.
*int p = null;
*p = 10; //this won't work as there is no memory backing up this pointer
p = new int;
*p = 10;
Problem
I have a pointer that points to null, and i want to assign it a value. But if i deference it, I get an error. I have tried this: ``` *nullPointer = value; ``` but like I said, I get an error. How can I do this?. I can't do ``` nullPointer = &value ``` Because later value (it's an object) is deleted and nullPointer would point to invalid memory.