0
What's the difference between pointer and reference?
1 Réponse
+ 2
There's a few differences. the biggest being that a pointer can have its value reassigned, whereas a reference variable cannot.
once a reference variable is created it's bound to the memory address it's referring to.
int a = 5;
int &b=a;//b = 5
a=4;//b=4
where a pointer works like this
int a=5;
int * ptr=&a;//ptr = 0xfffffff ,*p=5
int b=6;
*ptr=23;//a=23
ptr=&b;//ptr=0xffffffa,*ptr=6