Friday, October 22, 2010

'C' confusion

#include<stdio.h>
#include<conio.h>
void main()
{
          int a[5];
          int i;
         clrscr()
          for(i=0;i<10;i++)
          {
                  printf("enter the number:");
                  scanf("%d",a[i]);
          }
          for(i=0;i<10;i++)
          {
                  printf("the number at a[%d] is %d",i,a[i]);
           }
           getch();
}
Q- The array 'a' declared here is only of size 5, which means that it should accept only 5 numbers. But if we iterate it in a loop then it accepts the number of values more than or less than its original size. As example,consider the above program of C, in which array 'a[5]' should only accept 5 values but in loop of 0 to 9, it accepts 10 values.
What is the reason behind this?? if it accepts value according to the iteration of loop then what is the need to declare its size??

No comments:

Post a Comment