{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Lecture 02

# The caller cannot ignore pass by reference data send

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

This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: a was directly changed. Consider the Remainder Algorithm Remainder 1: Request a value for x 2: Request a value for y 3: while x y do 4: assign x-y to x 5: return x 6: end Call-by-value Caller a 20 b 7 x Algorithm A y Call-by-reference Caller a 20 b 7 x Algorithm A y Consider the Remainder Algorithm Remainder 1: Request a value for x 2: Request a value for y 3: while x y do 4: assign x-y to x 5: return x 6: end Call-by-value Caller a 20 b 7 20 x Algorithm A y Call-by-reference Caller a 20 b 7 x Algorithm A y Consider the Remainder Algorithm Remainder 1: Request a value for x 2: Request a value for y 3: while x y do 4: assign x-y to x 5: return x 6: end Call-by-value Caller a 20 b 7 20 7 x y Algorithm A Call-by-reference Caller a 20 b 7 x Algorithm A y Consider the Remainder Algorithm Remainder 1: Request a value for x 2: Request a value for y 3: while x y do 4: assign x-y to x 5: return x 6: end Call-by-value Caller a 20 b 7 13 7 x Algorithm A y Call-by-reference Caller a 13 b 7 x y Algorithm A Consider the Remainder Algorithm Remainder 1: Request a value for x 2: Request a value for y 3: while x y do 4: assign x-y to x 5: return x 6: end Call-by-value Caller a 20 b 7 6 7 x Algorithm A y Call-by-reference Caller a b 6 7 x Algorithm A y Consider the Remainder Algorithm Remainder 1: Request a value for x 2: Request a value for y 3: while x y do 4: assign x-y to x 5: return x 6: end Call-by-value Caller a 20 b 7 output 6 6 7 x Algorithm A y Call-by-reference Caller a b 6 7 output 6 x Algorithm A y Call-by-value Caller This output could be ignored. Call-by-reference can cause changes in the caller aside from returning output explicitly. a 20 b 7 6 6 7 x Algorithm A y Call-by-reference Caller a b 6 7 6 x Algorithm A y This output cannot be ignored. Mystery Algorithm What does the algorithm do? remainder(x, y) 1. Request a value for x 2. Request a value for y 3. while x y do 4. assign x y to x 5. return x 6. end Request a value for a Request a value for b if a b then assign b to c if a < b then assign a to c while (remainder(a, c)0 OR remainder(b, c) 0) subtract one from c return c end a) Computes the Least Common Denominator of 2 fractions b) Comput...
View Full Document

{[ snackBarMessage ]}