# UMBC CMSC 104 - Arrays, Part 1 of 2 (24 pages)

Previewing pages 1, 2, 23, 24 of 24 page document
View Full Document

## Arrays, Part 1 of 2

Previewing pages 1, 2, 23, 24 of actual document.

View Full Document
View Full Document

## Arrays, Part 1 of 2

44 views

Lecture Notes

Pages:
24
School:
University of Maryland, Baltimore County
Course:
Cmsc 104 - Problem Solving and Computer Programming
##### Problem Solving and Computer Programming Documents
• 18 pages

• 17 pages

• 9 pages

• 6 pages

• 15 pages

• 19 pages

• 21 pages

• 10 pages

• 19 pages

• 7 pages

• 12 pages

• 19 pages

• 19 pages

• 20 pages

• 39 pages

• 18 pages

• 12 pages

• 21 pages

• 4 pages

• 14 pages

• 18 pages

• 16 pages

• 16 pages

• 12 pages

• 5 pages

• 22 pages

• 25 pages

• 5 pages

• 23 pages

• 14 pages

• 4 pages

• 20 pages

• 21 pages

• 21 pages

• 21 pages

• 18 pages

• 27 pages

• 24 pages

• 40 pages

• 20 pages

• 22 pages

• 16 pages

Unformatted text preview:

Arrays Part 1 of 2 Topics Definition of a Data Structure Definition of an Array Array Declaration Initialization and Access Program Example Using Arrays Reading Sections 6 1 6 5 CMSC 104 Version 9 01 Data Types So far we have seen only simple data types such as int float and char Simple variables can hold only one value at any time during program execution although that value may change A data structure is a data type that can hold multiple values at the same time Synonyms complex data type composite data type The array is one kind of data structure CMSC 104 Version 9 01 Arrays An array is a group of related data items that all have the same name and the same data type Arrays can be of any data type we choose Arrays are static in that they remain the same size throughout program execution An array s data items are stored contiguously in memory Each of the data items is known as an element of the array Each element can be accessed individually CMSC 104 Version 9 01 Array Declaration and Initialization int numbers 5 The name of this array is numbers This declaration sets aside a chunk of memory that is big enough to hold 5 integers It does not initialize those memory locations to 0 or any other value They contain garbage Initializing an array may be done with an array initializer as in int numbers 5 5 2 6 9 3 numbers CMSC 104 Version 9 01 5 2 6 9 3 Accessing Array Elements Each element in an array has a subscript index associated with it numbers 5 0 2 1 6 2 9 3 3 4 Subscripts are integers and always begin at zero Values of individual elements can be accessed by indexing into the array For example printf The third element d n numbers 2 would give the output The third element 6 CMSC 104 Version 9 01 Accessing Array Elements con t A subscript can also be an expression that evaluates to an integer numbers a b 2 Caution It is a logical error when a subscript evaluates to a value that is out of range for the particular array Some systems will handle an out of range error

View Full Document

Unlocking...