mardi 2 juin 2015

Segmentation fault while reading Memory in C++

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;
}

After getting the address of int i, put in the following code :

#include <iostream>

using namespace std;

int main()
{
  volatile int *x = (volatile int *)0x7ffef9246e74; // [1]
  int y = *x;
  cout<<y<<endl;

  return 0;
}

[1] : I copied this line from this page.

On running the second code, I am getting segmentation fault (core dumped). Any help?

Aucun commentaire:

Enregistrer un commentaire