+ 1

C++ memory

Assume I know a hexadecimal memory location of an integer. By knowing that address, how can I get to the number? (The hexadecimal memory location that I know is NOT stored in a variable etc.. I just want to type it in code and get the number).

15th Aug 2021, 9:13 AM
Yahel
Yahel - avatar
1 Answer
+ 1
After testing... int value = 42; long address = (long)&value; int casted = *(int*)address; By converting the address to the pointer of the type and dereference it, you can get the value back. But honestly, I don't know if such use of addresses is valid. It looks like an abuse to me.
15th Aug 2021, 9:49 AM
CarrieForle
CarrieForle - avatar