I’m learning OOP, and I came across this question:
If we do this:
A* a = new A;
the new operator finds a space for the variable a from the heap. I want to know the address where that variable is situated.
Question 1
Which one is that address? What is the difference between this two?
cout << a;
cout << &a;
Question 2 (the main)
Let’s assume I do NOT delete the pointer. The program exits. As long as the pointer hasn’t been destructed by the class’s destructor, can I get back that object using it’s address (e.g. 0x0035fa24), when I run the program again? If yes, how?
ais the address of the object.&ais the address of the pointer.A typical modern OS would not allow you to do this. It will reclaim memory when the first process exits. No subsequently started process will be allowed to see the contents of the first process’s memory, since this would a major security risk.