Download presentation
Presentation is loading. Please wait.
Published byMarilyn Gibbs Modified over 9 years ago
1
Arrays (Chapter 5) Definition Applications One-Dimensional –Declaration –Initialization –Use Multidimensional
2
Definition (Wikipedia) In computer science an array[1] is a data structure consisting of a group of elements that are accessed by indexing. In most programming languages each element has the same data type and the array occupies a contiguous area of storage.
3
Applications Sample Data Vectors and Matrices –Systems of Linear Equations
4
Sample Data
5
2D Data
7
Matrices and Vectors
8
Declaration int main() { float sample;
9
Declaration int main() { float sample[10];
10
Declaration int main() { float sample[10]; sample[0], sample[1],... sample[8], sample[9]
11
Initialization int main() { float sample = 5.0;
12
Initialization int main() { float sample[10] = {5.0, 1.2, -4.6, -7.5, 8.9, -1.0, 12.7, 0.0, 6.6, 4.2};
13
Initialization int main() { float sample[10] = {5.0, 1.2, -4.6, -7.5, 8.9, -1.0, 12.7, 0.0, 6.6, 4.2}; sample[0] = 5.0, sample[1] = 1.2,... sample[9] = 4.2
14
Use...
15
Gotchas First element of array is [0]
16
Gotchas First element of array is [0] Last element of array is [n-1] (major source of bugs!)
17
Gotchas First element of array is [0] Last element of array is [n-1] (major source of bugs!) No bounds check (MAJOR source of impossible-to- find bugs!)
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.