0

Is is possible to directly store data into a memory location using C ?

To be more specific,

What if i want to store an integer data to a memory location starting from 00100000. Is it possible ?

Rupam
  • 1,502
  • 13
  • 23
  • 1
    Yes. Please don't do this. But yes. NOTE: my answer changes if you mean an actual *physical* address, rather than a virtual address. – Chris Eberle Apr 07 '14 at 21:36
  • 2
    You could `mmap()` the region containing the address... But you'd have to rely on the OS to actually honour your request. – EOF Apr 07 '14 at 21:37
  • also, there is no guarantee that whatever you pick isn't already in use...which will cause major problems. I can't think of an actual use case for this - what are you trying to accomplish? – Red Alert Apr 07 '14 at 21:38
  • 1
    Why do you want to do this? – Oliver Charlesworth Apr 07 '14 at 21:38
  • you know any computer you try this on has a virtual address space for userland programs. – Steve Cox Apr 07 '14 at 21:38

1 Answers1

0

Yes it is. You can do this: int*ptr = 00100000; And then do *(ptr) = 10; I highly recommend you don't do this however.