cout<<"in function"<<*a<<*b<<endl;
int temp = *a;
*a = *a + *b;
*b = abs(temp - *b);
}
int main() {
int a, b;
int *pa = &a, *pb = &b;
cin>>a>>b;
cout<<"maybe address of a and b respectively "<<&a<<" "<<&b<<endl;
cout<<"before into function"<<a<<b<<endl;
cout<<"value of pa and pb pointer before passing them into functions"<<*pa<<*pb<<endl;
update(pa, pb);
cout<<a<<endl<<b<<endl;
cout<<"value of pa and pb pointer after passing them into functions"<<*pa<<*pb<<endl;
cout<<"maybe address of a and b respectively "<<&a<<" "<<&b<<endl;
return 0;
}what does the pointer do here? should'nt I get the address of a and b when I cout'ed *pa and *pb respectively. aren't pointers used to store addresses of variable?
*<pointer> is essentially deferencing a pointer so you would get the value the pointer is pointing towards, :)
Обсуждают сегодня