I have two example codes:
array1.c example
Code:
int main ()
{
int test_scores[10];
int i;
printf("please enter the ten test scores now.\n");
for (i=0; i<10; i++)
{
printf("#%2d > ", i + 1);
scanf ("%d", &test_scores[i]);
}
printf("Thank you.\n");
return 0;
}
On this example I understand that there is a variable test_scores that is defined
as an array that has ten elements. The indices will be integers 0 though 9.
This program has errors in its boundaries.
bounds.c
Code:
int main()
{
int array[10];
int nextvar = 5;
int i;
printf( "nextvar is %d.\n", nextvar); /*is output so I should put &, correct?*/
for ( i=0; i<=10; i++); /*I do not understand the error here. Is it the <= sign?*
array[i]=i;
printf( "nextvar is now %d.\n", nextvar ); /*how should it look?*/
return 0;
}