Arrays are unique variables which can clasp more than one value under the same variable name, arranged with an index. Arrays are explained using a very simple syntax:
/* defines an array of 10 integers */ int numbers;
Accessing a number from the array is done using the same syntax. Observe that arrays in C are zero-based, which means that if we explained an array of size 10, then the array cells 0 through 9 (inclusive) are explained.
numbers is not a definite value.
int numbers; /* populate the array */ numbers = 10; numbers = 20; numbers = 30; numbers = 40; numbers = 50; numbers = 60; numbers = 70; /* print the 7th number from the array, which has an index of 6 */ printf("The 7th number in the array is %d", numbers);
Arrays can only have one kind of variable, because they are executed as a series of values in the computer’s memory. Because of that, retrieving a definite array cell is very efficient.
- The code below does not compile, because the
gradesvariable is missing.
- One of the grades is missing. Can you explain it so the grade average will be 85?