jeudi 2 avril 2015

How to recover an object from a pointer by passing it an hex address? [duplicate]


This question already has an answer here:




Pointers store memory addresses:



int val = 42;
int *p = &val;


Dereference operator recover objects:



std::cout << *p << std::endl;

42


Say that the val's memory address is:



std::cout << p << std::endl;

0x7fff9b2c9794


If I need read what is in a certain memory address?:



int *memAdd = 0x7fff9b2c9794;
std::cout << *memAdd << std::endl;


Error:



error: invalid conversion from ‘long int’ to ‘int*’ [-fpermissive]


How can I do that?


Aucun commentaire:

Enregistrer un commentaire