3. One-Dimensional Arrays
• A list of values with the same data type
that are stored using a single group
name (array name).
• Elements of the array are stored in
consecutive memory location.
• Only One dimension
• General array declaration statement:
data-type array-name[number-of-items];
• Example
float arr[SIZE];
4. One-Dimensional Arrays (cont.)
• Individual elements of the array can be accessed by
specifying the name of the array and the element's
index:
arr[3]
• Warning: indices assume values from 0 to number-of-
items -1 !!
5. One-Dimensional Arrays (cont.)
arr[0] arr[1] arr[2] arr[3] arr[4]
Skip over 3 elements to get the
starting location of element 4
The array name arr identifies the
starting location of the array
Start here
element 4
6. Some array terminology
• Size-No.of elements in an array is called the size of
the array.
• Type-The kind of values it can store.
• Array name-name of array
• Base or index address-memory location where the
first element of the array is located.
7. Some Array Terminology
mark[50]
mark[5]
mark[2]
mark[2] = 32;
Array name
Index - also called a subscript
- must be an int,
- or an expression that evaluates to an int
Indexed variable - also called an
element or subscripted variable
Note that "element" may refer to either a single indexed
variable in the array or the value of a single indexed variable.
Value of the indexed variable
- also called an element of the array
size
10. Memory address calculation
• Address of A[I]=
Base Address + size * (I - Lower Bound)
• Normally Lower Bound is 0,In some programming
language it will differ.