[enter image description here][1]First of all I declared array of 5 elements.
int a[5];
And then I assign 58 to a[8]
which is for experiment.
After I tried to print the value of a[8]
.I was shocked when I viewed the output as 58.
I feel its ok may be compiler allocated memory dynamically and so I wanna test with sizeof(a)
.The output was 20(5*4) then I be like hmm??
Check the demo program and of course my image too.
#include<stdio.h>
int main()
{
int a[5];
a[8]=58;
printf("\t a8=%d snd size of A= %d",a[8],sizeof(a));
}
The output was a8=58 snd size of A= 20
Note the fact that I practice the same with char
and of course on different devices.
Ultimately when I tried to assign 58 to a[15]
or increasing index then the output was 0 all the cases.enter image description here