13-Arrays-4up

1 25 and 57 write a loop to sum up all elements in

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ut the total to the screen. 3 24/07/11 9 24/07/11 10 Passing a full array ì Need two things to pass an array to a function: 1) Start of the array (memory address). 2) Size of the array (# elements). Function can handle any size of array. Arrays as function arguments Must tell it the size of the array separately. When calling, pass in the array (no !), and size. void showAllElements(char arr, int size) { int main () { cout << "Display all elements:\n"; const int N = 5; for (int i = 0; i < size; i++) { char myArray[N] = cout << arr[i] << " "; {'H', 'e', 'l', 'l', 'o'}; } // Pass the whole array. cout << endl; } Display all element...
View Full Document

This note was uploaded on 10/09/2012 for the course CMPT 125 taught by Professor Diana during the Spring '08 term at Simon Fraser.

Ask a homework question - tutors are online