Can anyone please explain the output for the following program? I get an infinite loop if used a[i] = 0;
and a segfault when I used a[i] = i;
and also the i
ranges between 0 - 9
when used a[i] = 0;
whereas it goes to 39 when used a[i] = i;
before giving a segfault.
#include<stdio.h>
#include<stdlib.h>
int mult(int a, int b);
int main()
{
int a[10];
int i = 0;
for(i=0; i < sizeof(a); i++)
{
a[i] = i;
printf("a[i]=%d i=%d\n", a[i], i);
}
return 0;
}