Also, I don't understand why it is an error ? I am simply passing value to the pointer which is accessing it from the struct. Later after I am done with it, I delete it. If you could maybe show me the correct code , in that case I can relate stuff because I am new to C++ :D the variable arr.array is an uninitialised pointer. It is an error to dereference an uninitialised pointer like this: arr.array[i] = savingArray; |
Let's look at a simple example.
That code is ok. But the code in your example was more like this:
In the last example, the pointer contains garbage, it could point to anything at all. If you attempt to store a value there, the program will attempt to modify the contents of some memory location somewhere. Sometimes the program will crash, but this is not guaranteed to happen, the program could silently corrupt some part of computer memory which may have unpredictable effects, not necessarily immediately. |