Title: Dale Roberts, Lecturer
1Department of Computer and Information
Science,School of Science, IUPUI
CSCI 230
Arrays Multidimensional Arrays
- Dale Roberts, Lecturer
- IUPUI
- droberts_at_cs.iupui.edu
2Multiple-Dimensional Arrays
- Multiple subscripted arrays
- Arrays require at least two subscripts to
identify a particular element - ANSI C standard allows at least 12 array
subscripts - 2D Arrays
- Tables with rows and columns (m by n array)
- Like matrices specify row, then column
A00 (2 subscripts) 2D array
(matrix) 2-dimensional vector
A scalar
A0 1D array 1-Dimensional vector
A common error is to use math matrix notation
a(1,2)
3Multiple-Subscripted Arrays
- Initialization
- int b22 1, 2 , 3, 4
- int c32 1, 2 , 3, 4 , 5, 6
- Initializers grouped by row in braces
- If not enough, unspecified elements set to zero
- int b 2 2 1 , 3, 4
- Referencing elements
- Specify row, then column
- printf( "d", b 0 1 )
1 2 3 4
Actual storage in the memory - rows by rows
-row-major
1 2 3 4 5 6
5 6
Â
4const indicates that the function does not modify
the array.
- Initialize variables
- Define functions to take double scripted arrays
- Initialize studentgrades
- Call functions minimum, maximum, and average
Each row is a particular student, each column is
the grades on the exam. Proper naming of the
defined constants is important to convey meaning.
5Why is it important to initialize lowGrade to the
highest possible grade, and highGrade to the
lowest possible grade?
6The array is 0 1 2
3 studentGrades0 77 68 86 73
studentGrades1 96 87 89 78
studentGrades2 70 90 86 81 Lowest
grade 68 Highest grade 96 The average grade for
student 0 is 76.00 The average grade for student
1 is 87.50 The average grade for student 2 is
81.75
Program Output