Lecture 7: Multi-Dimensional Arrays PDF

Document Details

HaleNeodymium

Uploaded by HaleNeodymium

Wilfrid Laurier University

Tags

arrays data structures multi-dimensional arrays programming

Summary

This document contains lecture notes on multi-dimensional arrays, covering two-dimensional arrays, their syntax, and various applications. Concepts such as array operations and data structures are also discussed.

Full Transcript

Lecture 7 Multi-Dimensional Arrays 1. Two-dimensional arrays 2. Multi-dimensional arrays 3. Applications of arrays 1 1. Two-dimensional arrays Concepts of two-dimensional arrays 1. A two-dimensional (simply 2-D or 2D) array is an array of arrays of the...

Lecture 7 Multi-Dimensional Arrays 1. Two-dimensional arrays 2. Multi-dimensional arrays 3. Applications of arrays 1 1. Two-dimensional arrays Concepts of two-dimensional arrays 1. A two-dimensional (simply 2-D or 2D) array is an array of arrays of the same type. 2. 2D array logically organizes m*n data elements of the same type in m arrays (rows) and each row is an array of n elements (or in row column style). The position of an element in 2D array can be represented by two subscripts, the first subscript denotes row index and the second denotes index in the row array. 3. The elements of a 2D array are physically stored in continues memory space in row major order, namely first row, second row, …, last row. 2 Two-dimensional (2D) array syntax Syntax: data_type array_name[row_count][column_count]; 1. It declares 2D array of row_count rows and column_count columns with row_count * column_count data_type elements. 2. It tells compiler to allocate a memory block of row_count * column_count * sizeof(data_type) bytes. 3. At runtime, the elements of 2D array are instanced in row major order, namely first row, second row array, and so on. 4. The element at row i and column j is represented as array_name[i][j], 0

Use Quizgecko on...
Browser
Browser