arrayfunction

# arrayfunction - Programming Passing Arrays to Functions ....

This preview shows pages 1–7. Sign up to view the full content.

Passing Arrays to Functions Programming

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

View Full Document
g. Fundamentals I: Passing Arrays to Function / Slide 2 Passing Arrays as Parameters Arrays are always passed by reference. The “[ ]” in the formal parameter specification indicates that the variable is an array. It is a good practice to pass the dimension of the array as another parameter. If the function must not change any element of the array then const should be used in the formal parameter specification of that array.
g. Fundamentals I: Passing Arrays to Function / Slide 3 Smallest Value Problem Find the smallest value in a list of integers Input A list of integers and a value indicating the number of integers Output Smallest value in the list Note List remains unchanged after finding the smallest value!

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

View Full Document
g. Fundamentals I: Passing Arrays to Function / Slide 4 Preliminary Design Realizations When looking for value with distinguishing characteristics, need a way of remembering best candidate found so far Best written as a function - likely to be used often Design Search array looking for smallest value Use a loop to consider each element in turn If current element is smallest so far, then update smallest value so far candidate When done examining all of the elements, the smallest value seen so far is the smallest value
g. Fundamentals I: Passing Arrays to Function / Slide 5 Necessary Information Information to be maintained Array with values to be inspected for smallest value Number of values in array Index of current element being considered Smallest value so far

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

View Full Document
g. Fundamentals I: Passing Arrays to Function / Slide 6
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 09/30/2010 for the course COMP COMP102 taught by Professor Lrr during the Fall '09 term at HKUST.

### Page1 / 18

arrayfunction - Programming Passing Arrays to Functions ....

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

View Full Document
Ask a homework question - tutors are online