Commit 3bc2c5ae authored by Tony Cheung's avatar Tony Cheung

Delete PassByPointer2.cpp

parent e8bc0bdb
#include <iostream>
using namespace std;
void swap(int **x, int **y)
{
int *t = *x;
*x = *y;
*y = t;
cout << "In the swap(), the value of x is: " << **x << endl;
cout << "In the swap(), the stored memory address of x is: " << hex << x << endl;
cout << "In the swap(), the value of y is: " << **y << endl;
cout << "In the swap(), the stored memory address of y is: " << hex << y << endl;
}
int main()
{
int *a = new int(1);
int *b = new int(2);
cout << "Before calling swap(), the value of a is: " << *a << endl;
cout << "Before calling swap(), the stored memory address of a is: " << hex << a << endl;
cout << "Before calling swap(), the value of b is: " << *b << endl;
cout << "Before calling swap(), the stored memory address of b is: " << hex << b << endl;
swap(&a, &b);
cout << "After calling swap(), the value of a is: " << *a << endl;
cout << "After calling swap(), the stored memory address of a is: " << hex << a << endl;
cout << "After calling swap(), the value of b is: " << *b << endl;
cout << "After calling swap(), the stored memory address of b is: " << hex << b << endl;
return 0;
}
// output
/*
Before calling swap(), the value of a is : 1
Before calling swap(), the stored memory address of a is : 014723F8
Before calling swap(), the value of b is : 2
Before calling swap(), the stored memory address of b is : 01472098
In the swap(), the value of x is : 2
In the swap(), the stored memory address of x is : 0133FE08
In the swap(), the value of y is : 1
In the swap(), the stored memory address of y is : 0133FDFC
After calling swap(), the value of a is : 2
After calling swap(), the stored memory address of a is : 01472098
After calling swap(), the value of b is : 1
After calling swap(), the stored memory address of b is : 014723F8
*/
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment