An interesting discussion about this started here but no one have been able to provide the C++ way of doing:
#include <stdio.h>
int main(void)
{
int* address = (int *)0x604769;
printf("Memory address is: 0x%p\n", address);
*address = 0xdead;
printf("Content of the address is: 0x%p\n", *address);
return 0;
}
What is the most appropriate way of doing such a thing in C++?
In C++, always prefer reinterpret_cast
over a C-cast. It's so butt ugly that someone will immediately spot the danger.
Example:
int* ptr = reinterpret_cast<int*>(0x12345678);
That thing hurts my eyes, and I like it.
There is NO standard and portable way to do so. Non-portable ways may include reinterpret_cast(someIntRepresentingTheAddress).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With