In the code I created an array of type Pessoa
containing only 2, but when it begins to iterate in the for loop and accesses index 2 and 3 the string continues without generating compile-time error nor execution. Is this behavior normal?
#include <stdio.h>
#include <windows.h>
typedef struct{
int num;
}Pessoa;
Pessoa pessoa[2];
int main (int argc, char *argv[])
{
const int count = 4;
for(int i = 0; i < count; i += 1){
pessoa[i].num = i;
}
for (int i = 0; i < count; i += 1)
{
printf("%d\n", pessoa[i].num);
}
system("pause");
return 0;
}
Program exit
0
1
2
3