Heloo GUYS ..I am passing an alias to pointer in function and in that function i am assigning pointer to another variable .This is changing the address of the pointer passed in main funtion .i'll show u example of my code .This gives the output 40.
#include <iostream>
using namespace std;
void foo(int* &p){
int z=40;
p=&z;
}
int main(){
int x=10;
int *p=&x;
foo(p);
cout<<*p;
}
But when I try to do this all in one main function then the address of the the pointer doesnt change so as the ouput..this is my code
#include<iostream>
using namespace std;
int main()
{
int a=1, b=2, c=3;
int *p, *q;
p=&a;
q=*&p;
p=&c;
cout<<*q<<endl;
}
it gives the ouput 1 rather then the 3.THANKs..