|
Introduction |
The variables we have used can only store one value .
int grade; //declares a single variable, named grade, of type int
What if we need to store the grades of 30 students , or more over for 1000 students ? should we declare 1000 variable ?
Here comes the usage of what we called the array.
A one dimensional array (single dimensional) is a list of values of the same data type ( variable that can hold more than one value) .
|
Declaring |
The items in the list can be declared as a single unit , and stored under a common variable name called array name.
int grades[30]; //declares an array, named grades, consisting of 30 elements, each of type int
Each array has sufficient memory reserved for it to hold the number of data items given in the declaration statement .
Examples:
char code[4]; // an array of 4 characters code
int grades[5]; // an array of 5 integers grades
code array with enough storage for 4 characters ( 4 bytes )
|
char |
char |
char |
char |
grades array with enough storage for 5 integers ( 10 bytes )
|
a grade |
a grade |
a grade |
a grade |
a grade |