I am just trying to get Value stored at a specific memory address using two C++ codes
Code which I using to write data to memory and get its address :
#include <iostream>
using namespace std;
int main()
{
int i = 10;
cout<<&i<<endl;
cin>>i; // This is just to make sure program doesn`t end
return 0;
}
I used cin>>i;
just to make sure that it doesn't end.
After getting the address of int i
, put in the following code :
#include <iostream>
using namespace std;
int main()
{
// This address changes everytime and I change it everytime
// This is just one temporary address
volatile int *x = (volatile int *)0x7ffef9246e74; // [1]
int y = *x;
cout<<y<<endl;
return 0;
}
[1] : I copied this line from this page.
Program #1 keeps running while I run Program #2
On running the second code, I am getting segmentation fault (core dumped)
. Any help?