Q:

Why Do I Get Different Memory Addresses For Pointer Passed To Function?

Basically my question is, when I run these two segments of code, I get different memory addresses. The first segment of code gives a certain memory address for rValue, and the second gives a different memory address for rValue, just by adding a & operator. Why does this happen?
#include <iostream>
using namespace std;

int pMem(int *rValue){

cout << "Value of rValue is " << *rValue << endl;;
cout << "Address of rValue is " << rValue << endl;
*rValue = 15;
cout << "Value of rValue now is " << *rValue << endl;
cout << "Address of rValue is " << rValue << endl;

return *rValue;

}

int main() {

int value = 8;
int *pValue = &value;

pMem(&value);

cout << "Value = " << value << endl;
cout << "Address of Value: " << pValue << endl;
cout << "Value at memory address " << pValue << ": " << *pValue << endl;

return 0;
}

2nd block of code, this time with the &rValue... I get a different memory address than the first block of code.
#include <iostream>
using namespace std;

int pMem(int *rValue){

cout << "Value of rValue is " << *rValue << endl;;
cout << "Address of rValue is " << &rValue << endl;
*rValue = 15;
cout << "Value of rValue now is " << *rValue << endl;
cout << "Address of rValue is " << &rValue << endl;

return *rValue;

}

int main() {

int value = 8;
int *pValue = &value;

pMem(&value);

cout << "Value = " << value << endl;
cout << "Address of Value: " << pValue << endl;
cout << "Value at memory address " << pValue << ": " << *pValue << endl;

return 0;

}

A:

Even pointers themselves take up memory and have an address associated with them.
So &rValue is the address of the the pointer rValue, and, unless it's a pointer to a function, that address will be different.

