I need to write 0x00001234 in the address 0x8000000, is it possible in C?
3 Answers
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;
1 Comment
Well if this is a beginner assignment in a c class i suspect it is turbo or borland c where you are programming in 16 bit environment with segment offset address scheme. In that case using an int * far ptr, with far being the pointer type to access address out of your current segment would be used. 0xb8000000 used to be the starting address of text mode video memory.
i.e.
int far * p = 0xB8000000;
*p = 'A'; // This would actually print char 'A' on screen
*(p+1) = <some number>; // this would determine the color of char A
Note that this used to be 16 bit programming. So a normal int * would be 16 bit and hence cannot access beyond current segment of memory.
We used to implement printf of our own by directly writing to video mem. This was a class assignment in c programming course over a decade ago. May be it matches your scenario.
This explanation might be helpful as well
mmapandMAP_FIXEDif you are using a POSIX OS.