It is necessary to fill an array of an integer type with 10 elements with the contents of the memory, starting with the cell with the address 0xf000. How can this be done?

PS The memory of the computer in this case we agree to count 640kb. If it changes anything.

  • one
    The point here is not the "clean" C, but the operating system. Access to physical memory is accomplished through the use of system calls and / or library functions associated with them. The information in question is not enough. - Vladimir Vodolazkiy
  • Which memory: virtual or physical? - skegg
  • For an application in a more or less common operating system, the address 0xf000 will be available only in DOS (if it can be considered common). In the rest, get a SIGSEGV signal. - avp 4:08 pm
  • In-in. By the way, why so? I know programming in dos very poorly. - skegg
  • There is no memory protection in DOS. - avp 4:39 pm

2 answers 2

If we are talking about a simple virtual memory process, then so

int buf[10]; int i; for (i = 0; i < 10; i++) buf[i] = *((int*) 0xf000 + i); 

Or so

 int buf[10]; memcpy (buf, (void*) 0xf000, sizeof(int)*10); 
  • Isn't memset used for this purpose? - Vladimir Gordeev
  • memset fills the bytes of the specified section of memory with the value specified there. - skegg

If I understood everything correctly then:

 main(){ int *a = 0; int arr[10]; int i=0; for(i=0; i <= 10; i++) arr[i]=a++; return 0; } 
  • one
    You fill the buffer with the values ​​of the address, not with the values ​​of the cells at these addresses. It is necessary to dereference the pointer. - skegg