-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPassByValueDEMO.cpp
More file actions
60 lines (45 loc) · 1.54 KB
/
Copy pathPassByValueDEMO.cpp
File metadata and controls
60 lines (45 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
//************************************************************************
// Author: Rolando Carreon
// Date: mar 6 2025
// Language: C++
// Assignment: PassByValueDEMO
// Description: swaps values using pass-by-value and pass-by-reference
// to show the way it affects varibales values
//************************************************************************
#include<iostream>
using namespace std;
// function protypes
void callByValue(int, int);
int main()
{
// declare local variables
int firstNumber = 10;
int secondNumber = 5;
// display values before any function calls
cout << "Before the callByValue.\n";
cout << "\t First Number: " << firstNumber << endl;
cout << "\t Second Number: " << secondNumber << endl;
// call the callByValue functin
callByValue(firstNumber, secondNumber);
// display values after callByValue
cout << "After the callByValue.\n";
cout << "\t First Number: " << firstNumber << endl;
cout << "\t Second Number: " << secondNumber << endl;
return 0;
}
// function definitions
// function that accepts two integers passed by value,
// swaps the values and displays the values
void callByValue(int numOne, int numTwo)
{
// declare variables
int temp;
// use temp to swap the value
temp = numOne;
numOne = numTwo;
numTwo = temp;
// display values inside callByValue function
cout << "Inside the callByValue.\n";
cout << "\t First Number: " << numOne << endl;
cout << "\t Second Number: " << numTwo << endl;
}