{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Chapter6

# Chapter6 - One Dimensional Arrays Engineering Problem...

This preview shows pages 1–3. Sign up to view the full content.

10/6/2009 Engineering Problem Solving with C++, Second Edition, J. Ingber 1 Engineering Problem Solving with C++, Etter Chapter 6 One-Dimensional Arrays One Dimensional Arrays ± Arrays ± Sorting Algorithms ± Searching Algorithms ± Character Strings ± The string Class. 10/6/2009 Engineering Problem Solving with C++, Second Edition, J. Ingber 2 ARRAYS Definition and Initialization Computation and Output Function Arguments 10/6/2009 Engineering Problem Solving with C++, Second Edition, J. Ingber 3 10/6/2009 Engineering Problem Solving with C++, Second Edition, J. Ingber 4 Definition ± An array is a data structure for storing a contiguous block of data. ± All data elements in an array must be of the same type. ± Individual elements of the array are specified using the array name and an offset . ± In C++ the offset of the first element is always 0.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
10/6/2009 Engineering Problem Solving with C++, Second Edition, J. Ingber 5 Definition and Initialization ± Syntax: data_type identifier [ size ] [= initialization list]; Note: size is an integer constant. ± Example: double m[8]; m[0] m[1] m[2] m[3] m[4] m[5] m[6] m[7] ? ? ? ? ? ? ? ? 10/6/2009 Engineering Problem Solving with C++, Second Edition, J. Ingber 6 Initializing Arrays ± Initializing array elements (initialization=>declaration) char vowels[5] = {'a', 'e', 'i', 'o', 'u'}; bool ansKey[] ={true, true, false, true, false, false}; char word[] = "Hello"; vowels 'a' 'e' 'i' 'o' 'u' true false false true false true ansKey word 'H' 'e' 'l' 'l' 'o' '\0' 10/6/2009 Engineering Problem Solving with C++, Second Edition, J. Ingber 7 Accessing Array Elements ± Offsets are used to access individual elements of an array. ± General format: array_identifier [ offset ] ± Example for (int i=0; i<=7; ++i) m[i] = double(i) + 0.5; ± Integer expressions may be used as offsets. 10/6/2009 Engineering Problem Solving with C++, Second Edition, J. Ingber 8 Functions and arrays ± An array identifier, without subscripts, references the starting address(first element) of the array. ± In C++, arrays are passed by reference. ie the starting address is passed, no size information.
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 8

Chapter6 - One Dimensional Arrays Engineering Problem...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online