Recently, I am learning the pointer of C, why can I apply for a space of one byte to put more than one content?

  c++, question

I am learning pointers recently. I just learned the empty pointer. I found that if I apply for 1 byte of space, I can actually assign 20 bytes of content and I haven’t reported anything wrong. why is that?

void *p = malloc(1);  //Allocate 20 bytes to null type pointer
 int *px = (int*)p;  //assign null pointer address to int pointer
 for (int i = 0;   i < 5;  i++) {
 
 px[i] = i+10;
 }
 for (int i = 0;   i < 5;  i++) {
 printf("\r\n%d",px[i]);
 }
 printf("%x",px);

The compiler does not check out of bounds. Array subscripts are not allowed to cross boundaries, not becauseThere is no storage space outside the boundary., but because the content outside the boundary is unknown.No matter whether the space outside the boundary is used or not, we can access that memory..

So, even if there is no definitiona[-1]Or ..A [I]/(I > a. length (), also accessible.

Compile phase fromaTake the first address and then take the offset according to the subscript to get *(a+i) this memory.

The benefits of not examining cross-border issues include:
1. If checked, the compiler must add additional code to the generated object code to detect whether the subscript is out of bounds when the program is running, resulting in a decrease in the running speed of the program
2. More Freedom