I have a written a simple c code as follows
#include<stdio.h>
void main()
{
int a[3];
int i;
for(i=0;i<=2;i++)
{
printf("i is %d\n",i);
scanf("%d ",&a[i]);
}
for(i=0;i<=2;i++)
printf("a[%d] is %d\n",i,a[i]);
}
The problem is when I run the program I have to enter two values when i is 0(not one) like this
i is 0
1
2
i is 1
3
i is 2
4
Even though the output is correct i.e.
a[0] is 1
a[1] is 2
a[2] is 3
why do I have to enter 4 values instead of 3 and why do the statement i is 1 not come before I enter 2?