Arrays and Strings - Base Address of an Array Functions...

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

View Full Document Right Arrow Icon
Arrays and Strings Arrays dataType arrayName[intExp]; int nbr[5]; Accessing Array Components arrayName[indexExp] int list[10]; list[5] = 34; i = 3; list[i] = -15; const int arraySize = 10; int list[arraySize]; Processing One-Dimensional Arrays for (i = 0; i < arraySize; i++) process list[i]; initialize, input, output, find largest, find smallest, find sum & average, find element (search) sort Array Index Out of Bounds Array Initialization During Declaration double sales[] = {12.25, 32.50, 23.65, 26, -45.67}; Partial Initialization of Arrays During Declaration int list[10] = {0}; int list[10] = {1,2,3}; int list[ ] = {1,2,3};
Background image of page 1

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

View Full Document Right Arrow Icon
Some Restrictions on Array Processing Aggregate operations array1 = array2; // illegal cin >> array1; cout << array2; if (array1 < array2) Arrays as Parameters to Functions By reference void initialize (int list[], int size); Constant Arrays as Formal Parameters Void example (int x[ ], const int y[ ]);
Background image of page 2
Background image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Base Address of an Array Functions Cannot Return a Value of the Type Array Integral Data Types and Array Indices enum paintType {Green, Red, Blue, Brown, White, Orange, Yellow}; double paintSale[7]; paintType paint; for (paint = Green; paint <= Yellow; paint = static_cast<paintType>(paint+1)) paintSale[paint] = 0.0; Other Ways to Declare Arrays const int size = 50; typedef double list[size]; list a; list myList; C-Strings (Character Arrays Terminated with null character (‘\0’) char studentName[26]; studentName = “Wayne Summers”; //illegal include <cstring> strcpy(s1, s2); strcmp(s1, s2); strlen(s) String Input cin >> name; //illegal cin.get(str, size+1); String Output cout << name; Specifying Input/Output Files at Execution Time The String Type and Input/Output Files strVar.c_str() used to convert String Type to c-string Parallel Arrays...
View Full Document

{[ snackBarMessage ]}

Page1 / 3

Arrays and Strings - Base Address of an Array Functions...

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