Java / C++ developer here. Trying to learn C but I am confused with memory allocation for arrays.
What is happening here?
#include <stdlib.h>
#include <stdio.h>
#include <windows.h>
int main()
{
int az[3];
az[2] = 66;
az[8] = 5214;
printf("%d\n", az[8]);
system("pause");
return 0;
}
Output
5214
How can that be ? Why do I not get Out of Bounds exception or a program crash? I can I do this infinitely? What is my array's length in this case? What's the point of allocating memory via malloc
if my arrays allow me to already put values out of bounds? This makes zero sense to me.