Chapter6 - One Dimensional Arrays Engineering Problem...

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

View Full Document Right Arrow Icon
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.
Background image of page 1

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

View Full DocumentRight Arrow Icon
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. ± Arrays in C++ to not know their size.
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 10/23/2011 for the course ECE 224 taught by Professor Wangxin during the Spring '09 term at SUNY Stony Brook.

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 Right Arrow Icon
Ask a homework question - tutors are online