Presentation is loading. Please wait.

Presentation is loading. Please wait.

Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 13: Pass-by-Value?!?

Similar presentations


Presentation on theme: "Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 13: Pass-by-Value?!?"— Presentation transcript:

1 Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 13: Pass-by-Value?!?

2 In This Lesson We Will: Explore the passing of arrays to methods Explore the passing of arrays to methods Re-visit the concept of “pass-by-value” Re-visit the concept of “pass-by-value”

3 Topic Pass-by-Value Revisited

4 Review Our Array-Sort Study the methods we wrote for our array-sorting program Study the methods we wrote for our array-sorting program Arrays are passed parameters Arrays are passed parameters Are they value or variable parameters? Are they value or variable parameters? We made changes to the array in the methods – did those persist? We made changes to the array in the methods – did those persist?

5 Pass-by-Value?!? The values moved - how can this be? The values moved - how can this be? This highlights a confusing characteristic of the pass-by-value concept This highlights a confusing characteristic of the pass-by-value concept You must know WHAT is being copied You must know WHAT is being copied In the case of an array, what is copied actually is the array reference (pointer), not the array itself In the case of an array, what is copied actually is the array reference (pointer), not the array itself

6 Copying Arrays The effect of this approach is that you must be careful when passing arrays and other complex structures The effect of this approach is that you must be careful when passing arrays and other complex structures What is copied is likely to be the pointer, or reference: this is a shallow copy What is copied is likely to be the pointer, or reference: this is a shallow copy To make a deep copy create a new array and copy the elements To make a deep copy create a new array and copy the elements

7 In This Lesson We Have: Used arrays as method parameters Used arrays as method parameters Identified a complication to the concept of “pass-by-value” Identified a complication to the concept of “pass-by-value”


Download ppt "Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 13: Pass-by-Value?!?"

Similar presentations


Ads by Google