Recently, I had free time at school for several days and wanted to do a little experiment in C ++ dedicated to the memory address.
I would like to see that if the current running program (let it call program A) that created a pointer to an int object on the heap, you can see another program and change it (program B).
So, for program A, this is my base code:
#include <iostream>
using namespace std;
int main()
{
int *pint = new int(15);
cout << pint << endl;
cout << *pint << endl;
return 0;
}
Output for program A:
0x641030
15
In program B, I looked at how to assign a specific memory address from this link:
http://www.devx.com/tips/Tip/14104
Code for program B:
#include <iostream>
using namespace std;
int main()
{
int *p = reinterpret_cast< int* > (0x641030);
cout << p << endl;
cout << *p << endl;
return 0;
}
Output for program B:
0x641030
... "Crash"
I do not quite understand. I was expecting 15 of to display *p, but it did what I did not expect.
*p , *p = 2000, , .
, A (cout << &pint;) B (cout << &p;), .
- , ? , . , , , ++/C?
** **
, , Window 7 Professional