I have this code:
#include <stdio.h>
int main()
{
int arr2[5];
arr2[0] = 0;
arr2[1] = 1;
arr2[2] = 2;
arr2[3] = 3;
int arr3[5] = {1, 2, 3, 4};
}
And when I'm printing the fifth position of each array I'm getting different results:
printf("Fifth: %d\n", arr2[4]); // Prints Random number
printf("Fifth: %d\n", arr3[4]); // Prints Zero!
output:
Fifth: -858993460
Fifth: 0
I understand that the first is a pointer to the location of the fifth in the memory, and the second one is just how the array was initialized with 0. I don't understand why they give me 2 different values. I have set the size of the array to 5 in both cases; why is this happening?