0
What is the difference(s) between pointers and references?
Int x = 2; Int *pi = &x; //pointer Int &y = x;//reference
2 odpowiedzi
+ 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
+ 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.