I need to write 0x00001234 in the address 0x8000000, is it possible in C?
So not to happen all these, two variables can't have same addresses not in c, anywhere, you can transfer a variable address to store in a variable, later you will learn more about this topic in pointers in c language, Hope you understood!!
To access address of a variable to a pointer, we use the unary operator & (ampersand) that returns the address of that variable. For example &x gives us address of variable x.
The memcpy function is used to copy a block of data from a source address to a destination address.
To print the memory address, we use '%p' format specifier in C. 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.
If you work with hardware register in embedded system then standard way is:
int volatile * const p_reg = (int *) 0x8000000;
*p_reg = 0x1234;
You can have a lot of problems with optimizing compiler, if you omit volatile
You can, but you will have a segfault 99.9999..9% of the time because your program won't have access on this memory address.
int *nb = (int *) 0x8000000;
*nb = 0x00001234;
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