Professional Documents
Culture Documents
Introduction
An array is a collection of variables of the same type. Each of the
variables in an array are referred to as elements and each of these
elements can be accessed by its index. Arrays can be
multidimensional, which means that arrays can form matrixes cubes
and more. Arrays are useful when sorting many elements of the same
data type and searching through them.
All of the elements in an array can be accessed by its index. The first
element will be located in the index 0 and the second element would
be located in the index 1. Arrays are created in the format: arrayName
= new arrayType[arraySize]. In the figure below the integer array
intArray is being declared and it contains 3 elements. The element at
the index 2 is being assigned
to the integer 32.
2
Loops are also useful to print the elements of an array. In order to print
a specific element, you would need to know the index of that element.
The figure below shows a loop that would print out the elements of the
integer array from above.
Multidimensional Arrays
Multidimensional arrays are arrays two, three, or more dimensions. Two
dimensional arrays can be represented as matrixes. A two dimensional
array can be displayed as a table on paper, with rows and columns.
The format for a two dimensional array is: arrayName[rowIndex]
[columnIndex]. A three
dimensional array would
be the same but with a
third [index]. The figure
below shows a two dimensional integer array.
5
Conclusion
Arrays are extremely useful in sorting and searching through large
amounts of data. A bubble sort can be used to sort number arrays in
ascending order and a binary search can be used to find the location of
an element within that array. Arrays can have multiple dimensions
which are basically one dimensional arrays that reference to other one
dimensional arrays. Each of these arrays gets its own block of memory.
Loops are mainly used when processing and printing arrays. Arrays
make it easy to hold large amounts of data and sort through them.
Works Cited
Cheung, Shun. Array of char in memory. Digital image. Emory University. Emory
University, n.d. Web. 27 Nov. 2016.
6