int arr[5]={1,2,3,4,5,6,7,8,9};
This way of declaration is not giving an error and the array is stored up till the 4th index, if I try to output arr[5] it will give garbage value. Can anyone explain how this way is possible?
Edit: I was trying to run the following code in an online compiler:
#include <stdio.h>
int main() {
int arr[5]={1,2,3,4,5,6,7,8,9};
int i;
for(int i=0; i<6;i++){
printf("arr[%d]=%d\n", i,arr[i]);
}
return 0;
}
-pedantic-errorsif you're usinggccorclang,/permissive-if you are using MSVC. The program has undefined behavior anyway though.