Download presentation

Presentation is loading. Please wait.

Published byJaden Royal Modified about 1 year ago

1
PASSING PARAMETERS 1

2
2 Parameter Passing (by Value) Parameters Formal Parameters – parameters listed in the header of the function Variables used within the function to perform a task Actual Parameters - parameters listed in the function call Actual data being passed to the function for use within the function

3
3 Parameter Passing (by Value) void print_nums (int num1, int num2, int num3); { cout << endl; cout << “Number 1 is : “ << num1 << endl; cout << “Number 2 is : “ << num2 << endl; cout << “Number 3 is : “ << num3 << endl; } Formal Parameters

4
4 Parameter Passing (by value) int main( ) { number_1 = 10; number_2 = 20; number_3 = 30; cout << “The Numbers are: “ << endl; print_nums ( number_1, number_2, number_3 ); cout << system(“Pause”); } Actual Parameters

5
5 Parameter Passing (by Value) void print_nums ( int num1, int num2, int num3) { Number_1 = 10; Number_2 = 20; Number_3 = 30; print_nums ( number_1, number_2, number_3 ); cout << system(“Pause”); } num1 num2 num3 number_1 number_2 number_3 10 20 30 10 num1 20 num2 30 num3

6
6 Parameter Passing (by Value) The Numbers are: Number 1 is : 10 Number 2 is : 20 Number 3 is : 30 Screen

7
7 Parameter Passing (by Reference) void print_nums ( int num1, int num2, int& num3); { num3 = num1 * num2; cout << endl; cout << “Number 1 is :” << num1 << endl; cout << “Number 2 is :” << num2 << endl; cout << “Number 3 is :” << num3 << endl; } Variable Parameter

8
8 Parameter Passing (by Reference) int main( ) { number_1 = 10; number_2 = 20; number_3 = 30; cout << “The Numbers are: “ << endl; cout << number_1 << number_2 << number_3 << endl; print_nums ( number_1, number_2, number_3 ); cout << “The Numbers are: “ << endl; cout << number_1 << number_2 << number_3 << endl; cout << system(“Pause”); } Actual Parameters

9
9 Passing by Reference void print_nums ( int num1, int num2, int& num3) { number_1 = 10; number_2 = 20; number_3 := 30; print_nums ( number_1, number_2, number_3 ); } num1 num2 num3 10 number_1 20 number_2 30 number_3 400 404 408 10 num1 20 num2 add 408 num3 address 10 number_1 20 number_2 200 number_3

10
10 Passing by Reference The Numbers are: 10 20 30 Number 1 is : 10 Number 2 is : 20 Number 3 is : 200 The Numbers are: 10 20 200 Screen

Similar presentations

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google