Here is an Array program.
Practice.c
#include <stdio.h>
void main()
{
int i,num[10]={10,20,30,40,50};
for(i=0;i<15;i++)
{
printf("\nnum[%d] =%d",i,num[i]);
}
}
Following is the output of the Program.
num[0] =10
num[1] =20
num[2] =30
num[3] =40
num[4] =50
num[5] =0
num[6] =0
num[7] =0
num[8] =0
num[9] =0
num[10] =10
num[11] =0
num[12] =2686711
num[13] =2686820
num[14] =4199443
Now I have 2 questions:
1- Why is num[5] to num[9]
displayed there values as 0
?
2- Why num[10] to num[14]
are displaying these values, when I only have declared the length as int num [10]
and not as int num [15]
, shouldn't the program be displaying an error while running or compiling?