What's the difference between pointer and reference? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

What's the difference between pointer and reference?

4th Aug 2016, 5:07 AM
Bill Li
Bill Li - avatar
1 Answer
+ 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
4th Aug 2016, 4:56 PM
destro