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

Just assign the address to a pointer:

char *p = (char *)0xff73000;

And access the value as you wish:

char first_byte = p[0];
char second_byte = p[1];

But note that the behavior is platform dependent. I assume that this is for some kind of low level embedded programming, where platform dependency is not an issue.


Two ways:

1. Cast the address literal as a pointer:

char value = *(char*)0xff73000;

Cast the literal as a pointer to the type.

and

De-reference using the prefix *.

Same technique applies also to other types.

2. Assign the address to a pointer:

char* pointer = (char*)0xff73000;

Then access the value:

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

Where char is the type your address represents.


char* p = 0x66FC9C;

This would cause this warning :

Test.c: In function 'main': Test.c:57:14: warning: initialization makes pointer from integer without a cast [-Wint-conversion] char* p = 0x66FC9C;

To set a certain address you'd have to do :

char* p = (char *) 0x66FC9C;