I am just trying out arrays in c.In which i have following fundamental doubts?
#include <stdio.h>
int main()
{
int a[5]={1,2,3,4,5};
a[45]=28; // trying to access the random array element which is out of bound
printf("\n value at a[5] is %d",a[5]);
printf("\nvalue at a[45] is %d",a[45]);
printf("\nvalue at a[78] is %d",a[78];
return 0;
}
The above program compiles successfully and produces following output.
value at a[5] is 1234355 // some ando address
value at a[45] is 28 // which i have assigned
value at a[78] is 0
my question are
i) when i am accessing array element out of bound .whys it is not generating any error?
ii) For char array eg : char[10]= {'1','2','3','4','5','6','7','8','9','0'};
last element of the array will be '\0' added by compiler .is any like that for integer array?if not why?
iii) is it possible to redefine the array?