7-Arrays

7-Arrays - C+ Programming: Arrays Objectives In this...

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

View Full Document Right Arrow Icon
C++ Programming: Arrays
Background image of page 1

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

View Full DocumentRight Arrow Icon
Objectives In this chapter you will: Learn about arrays Explore how to declare and manipulate data into arrays Understand the meaning of “array index out of bounds” Become familiar with the restrictions on array processing Discover how to pass an array as a parameter to a function
Background image of page 2
Arrays Array - a collection of a fixed number of components wherein all of the components have the same data type One-dimensional array - an array in which the components are arranged in a list form The general form of declaring a one- dimensional array is: dataType arrayName[intExp]; where intExp is any expression that evaluates to a positive integer
Background image of page 3

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

View Full DocumentRight Arrow Icon
Declaring arrays The statement int num[5], i = 4 ; declares an array num of 5 components of the type int The components are num[0] , num[1] , num[2] , num[3] , and num[4] Num[i] = 34 ; The statement Person People[5], P1(“John”,”doe”); declares an array people of 5 components of the type Person (User defined type) The components are People [0] , People [1] , People [2] , People [3] , and People [4] People[i] = P1 ;
Background image of page 4
Background image of page 5

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

View Full DocumentRight Arrow Icon
People 0 1 2 3 4 “ “ “ “ “ “ “ “ “ “ Jones “ “ “ “ John Doe An array containing objects To access use [ ] operator cout<< People[4].Get_name() ; People[2].Set_last(“Jones”) ;
Background image of page 6
Accessing Array Components The general form (syntax) of accessing an array component is: arrayName[indexExp] where indexExp , called index , is any expression whose value is a nonnegative integer Index value specifies the position of the component in the array The [] operator is called the array subscripting operator The array index always starts at 0
Background image of page 7

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

View Full DocumentRight Arrow Icon
Background image of page 8
Background image of page 9

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

View Full DocumentRight Arrow Icon
Background image of page 10
Background image of page 11

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

View Full DocumentRight Arrow Icon
Processing One-Dimensional Arrays Some basic operations performed on a
Background image of page 12
Image of page 13
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 05/03/2009 for the course CSCI 101L taught by Professor Ghyam during the Spring '07 term at USC.

Page1 / 37

7-Arrays - C+ Programming: Arrays Objectives In this...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online