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

I wanted to read the value that is stored at an address whose absolute value is known. I wonder how I can achieve this. For instance. If the value is stored in 0xff73000. Then you can get the value stored here through code C. Thanks in advance

+4
source share
2 answers

Just assign the address to the pointer:

char *p = 0xff73000; 

And access the value as you like:

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

But note that the behavior is platform dependent. I guess this is for some kind of low-level embedded programming where platform dependency is not a problem.

+6
source

Two ways:

1. Insert the address literal as a pointer:

 char value = *(char*)0xff73000; 

2. Assign an address to the pointer:

 char* pointer = 0xff73000; 

Then access the value:

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

Where char is the type that represents your address.

+5
source

Source: https://habr.com/ru/post/1501645/


All Articles