I have a long-term fear of pointers and I am trying to start from the beginning to make my roots strong. As basic as this question may seem, can someone address this query? Would be of great help. I am basically trying to pass by reference. Why doesn't the function myf2 work?. The output is coming as:
Values: d=0, y=25 Values: d=25, y=25
CODE:
#include<iostream>
using namespace std;
void myf2(int *x, int *y)
{
x=y;
}
int* myf3(int *y)
{
return y;
}
int main()
{
int *d, a=25;
d = new int;
int *y = new int;
y=&a;
myf2(d,y);
cout<<"Values: d="<<*d<<", y="<<*y<<endl;
d=myf3(y);
cout<<"Values: d="<<*d<<", y="<<*y<<endl;
return 0;
}