Consider:
#include <stdio.h>
#include <stdlib.h>
int main()
{
int *numeros = malloc(sizeof(int) * 3 * 3);
numeros[900] = 10;
printf("%d", numeros[900]);
free(numeros);
return 0;
}
Why exactly does this print out 10 when I haven’t allocated enough memory?
I’m pretty sure I’m missing something big on pointers, etc.
What you observe is undefined behavior – you write outside the allocated buffer and likely overwrite some memory that happens to be mapped into the process.
Depending on various factors this might crash your program or just do nothing or corrupt data in the program. Don’t do it, only access memory that you’ve legally allocated.
Also see this related question.