arrayfunction

arrayfunction - Programming Passing Arrays to Functions ....

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

View Full Document Right Arrow Icon
Passing Arrays to Functions Programming
Background image of page 1

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

View Full DocumentRight Arrow Icon
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.
Background image of page 2
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!
Background image of page 3

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

View Full DocumentRight Arrow Icon
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
Background image of page 4
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
Background image of page 5

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

View Full DocumentRight Arrow Icon
g. Fundamentals I: Passing Arrays to Function / Slide 6
Background image of page 6
Image of page 7
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 Right Arrow Icon
Ask a homework question - tutors are online