0

What is the difference(s) between pointers and references?

Int x = 2; Int *pi = &x; //pointer Int &y = x;//reference

23rd Oct 2019, 11:39 PM
M Irdmousa
M Irdmousa - avatar
2 Réponses
+ 1
Sir, Pointers is a block of memory which does the job of storing memory address of another block of memory Reference is a kinda function which does the job of taking memory address of a block of memory and then sending it into a pointor. Pointers are useful because instead of coping the same data again and again you just take its address and use it to prevent unnecessary coping. https://code.sololearn.com/c4qbm7cjs2DA/?ref=app
24th Oct 2019, 1:31 AM
Dev Pratap
Dev Pratap - avatar
+ 1
And Ya Int * y = x; is wrong Correct way is Int * y = &x; And by. Int & y = x; It does the same job as above * But it automatically makes y a * and passes the memory address of x.
24th Oct 2019, 1:37 AM
Dev Pratap
Dev Pratap - avatar