|
#include <iostream>
int sub (int *, int *); // Declaring the sub function and having two pointer pointers for integers
int main ()
{
using namespace std;
int a = 100, b = 200;
cout << "Before, print a and b:" << a << "and" << b << "\n";
cout << "Go to sub () ..." << "\n";
sub (&a,&b); // pass the addresses of integers a and b to sub ()
cout << "After, print a and b:" << a << "and" << b << "\n";
return 0;
}
int sub (int * x, int * y) // x, y is the address of a and b, passed into the function
{
int temp;
temp = * x; // Assign the value at X address to the integer temp
* x = * y; // Assign the value at y address to the memory pointed to by x address
* y = temp; // Assign the value of integer temp to the memory pointed to by y
return * x, * y; // Return the values at x and y addresses
}
Is this understanding correct in the comments ???? |
|