Arrays
Arrays
What are Arrays?
- A group of memory locations that have the same name and store
the same type of data
- A particular element (value) in an array can be referenced by the
common name and the location number within that name
- Example:
Array grades
Array Element | Array Element Values |
---|
grades[0] | 65 |
grades[1] | 72 |
grades[2] | 56 |
- In C and C++ the first element in the array is the zeroth element
- The array grades has three elements, numbered 0 through
2
- The array name is grades
- Each element of the array is referenced by using the array name and
the
position of the element within the array - this is called the
subscript
- The subscripts may also be arithmetic expressions: e.g.,
grades[a+b], where a and b are integer
values
- References to array elements outside the bounds of an array can lead
to unpredicatble logical errors. C/C++ does not provide array bound
checking
- The square brackets used to define the subscript value is an operator
in C/C++
Back to Previous Page
Document:
Local Date:
Last Modified On: