How to read a value from an absolute address through C code

niteshnarayanlal picture niteshnarayanlal · Sep 11, 2013 · Viewed 55.4k times · Source

I wanted to read a value which is stored at an address whose absolute value is known. I am wondering how could I achieve this. For example. If a value is stored at 0xff73000. Then is it possible to fetch the value stored here through the C code. Thanks in advance

Answer

Zdeněk Gromnica picture Zdeněk Gromnica · Mar 24, 2016

Two ways:

1. Cast the address literal as a pointer:

char value = *(char*)0xff73000;

2. Assign the address to a pointer:

char* pointer = (char*)0xff73000;

Then access the value:

char value = *pointer;
char fist_byte = pointer[0];
char second_byte = pointer[1];

Where char is the type your address represents.