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.
Pointers refer to a location in memory (RAM). When you have a
null pointerit 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.