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
Printing pointers. You can print a pointer value using printf with the %p format specifier. To do so, you should convert the pointer to type void * first using a cast (see below for void * pointers), although on machines that don't have different representations for different pointer types, this may not be necessary.
Address in CIf you have a variable var in your program, &var will give you its address in the memory. We have used address numerous times while using the scanf() function. scanf("%d", &var); Here, the value entered by the user is stored in the address of var variable. Let's take a working example.
To print the address of a variable, we use "%p" specifier in C programming language. There are two ways to get the address of the variable: By using "address of" (&) operator. By using pointer variable.
In C programming language, *p represents the value stored in a pointer. ++ is increment operator used in prefix and postfix expressions.
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.
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