I have a question about the following code. I am not sure why the address stored in yAdd doesn't get updated to the same address stored in the variable x inside the addfun() function in the code below? what is wrong with my thinking?
#include <iostream>
using namespace std;
void fun(int *x) {
*x = 55;
}
void addfun(int **x) {
*x = new int[3];
cout << x << endl; // x stores the address of int[0]
// say it is 0x7ffc32e646a0
cout << &x << endl;
}
int main()
{
int y = 99;
int *yAdd = &y;
cout << y << endl;
fun(yAdd);
cout << y << endl;
cout << yAdd << endl; // original address stored in yAdd
cout << "address of y is " << &y << endl;
addfun(&yAdd); // so I update the address stored in yAdd to be the same address
// as stored inside the x in the addfun function
cout << yAdd << endl; // but how come when printing this, yAdd doesn't
// show 0x7ffc32e646a0, but something else?
return 0;
}