10.3.1 Reading a String from the Keyboard Arrays and Strings
[Pages:24]Chapter 10
Arrays and Strings
10.1 Arrays 10.2 One-Dimensional Arrays
10.2.1 Accessing Array Elements 10.2.2 Representation of Arrays in Memory 10.2.3 Example: Finding the Maximum 10.2.4 No Array-to-Array Assignments 10.2.5 No Bounds Checking
10.3 Strings
10.3.1 Reading a String from the Keyboard 10.3.2 Some C++ Library Functions for Strings 10.3.3 Using the Null Terminator
Chapter Overview
? Christian Jacob
10.4 Two-Dimensional Arrays 10.5 Multidimensional Arrays 10.6 Array Initialization
10.6.1 Character Array Initialization 10.6.2 Multi-Dimensional Array Initialization 10.6.3 Unsized Array Initializations
10.7 Arrays of Strings 10.8 An Example Using String Arrays
10.8.1 Entering Information 10.8.2 Displaying Database Contents 10.8.3 Menu For User?s Selection 10.8.4 Main Function 10.8.5 Putting It All Together
10.9 References
Chapter Overview
? Christian Jacob
Page 3
Chapter 10: Arrays and Strings
? Christian Jacob
10.1 Arrays
An array is a collection of variables of the same type that are referred to by a common name.
Arrays offer a convenient means of grouping together several related variables, in one dimension or more dimensions:
? product part numbers: int part_numbers[] = {123, 326, 178, 1209};
? student scores: int scores[10] = {1, 3, 4, 5, 1, 3, 2, 3, 4, 4};
? characters: char alphabet[5] = {'A', 'B', 'C', 'D', 'E'};
First Back TOC
Prev Next Last
Page 4
Chapter 10: Arrays and Strings
? Christian Jacob
? names:
char names[][40] = {"Peter", "Mary", "Lisa", "John", "George-Simon"};
? 3D coordinates:
vector coordinates[4][3] = {{0, 0, 0}, {1, 0, 1}, {1, 0, 5} {4, 7, 9}};
First Back TOC
Prev Next Last
Page 5
Chapter 10: Arrays and Strings
? Christian Jacob
10.2 One-Dimensional Arrays
A one-dimensional array is a list of related variables. The general form of a one-dimensional array declaration is:
type variable_name[size]
? type:
base type of the array, determines the data type of each element in the array
? size:
how many elements the array will hold
? variable_name: the name of the array
Examples: int sample[10];
float float_numbers[100];
char last_name[40];
First Back TOC
One-Dimensional Arrays
Prev Next Last
Page 6
Chapter 10: Arrays and Strings
? Christian Jacob
10.2.1 Accessing Array Elements
An individual element within an array is accessed by use of an index. An index describes the position of an element within an array. Note: In C++ the first element has the index zero!
First Back TOC
One-Dimensional Arrays
Prev Next Last
Page 7
Chapter 10: Arrays and Strings
? Christian Jacob
Example: Load the array sample with the numbers 02 through 92
#include
int main() {
int sample[10]; // reserves for 10 integers int t;
// initialize the array
for(t=0; t ................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.
Related searches
- a verse from the bible
- 3 10 minus 1 4
- 3 10 minus 1 6
- windows 10 usb 3 1 driver download
- letters to a friend from the heart
- a raisin in the sun act 1 scene 1 questions 1 20
- activity 1 1 match the word from the first column with the correct definition
- 3 1 what are the hexadecimal bytes for the following instructions a inc dptr
- 3 1 what are the hexadecimal bytes for the following instructions
- the semicircle from the scale drawing will be cut in full size from a piece of f
- guided reading activity 3 1 earth sun relationships
- remove a character from a string python