0

Difference between call by address and call by reference

12th Sep 2017, 3:13 PM
Ashwin Bhawsar
Ashwin Bhawsar - avatar
3 odpowiedzi
+ 1
int &x = variable is a direct reference to the address of variable int *x = &variable is a pointer to a reference of a variable. here are some differences from stack overflow -A pointer can be re-assigned any number of times while a reference cannot be re-seated after binding. -Pointers can point nowhere (NULL), whereas reference always refer to an object. -You can't take the address of a reference like you can with pointers. -There's no "reference arithmetics" (but you can take the address of an object pointed by a reference and do pointer arithmetics on it as in &obj + 5) there are other syntax differences that you should know like when referencing a class you can access it like normal e.g. x.value but with a pointer you have to do x->value or (*x).value to access it.
12th Sep 2017, 3:39 PM
Enzo
Enzo - avatar
0
you mean a pointer and a reference? if i understand it correctly there is no difference between what youre asking.
12th Sep 2017, 3:23 PM
Enzo
Enzo - avatar
0
int Sum(int *x) and int Sum(int &x)
12th Sep 2017, 3:25 PM
Ashwin Bhawsar
Ashwin Bhawsar - avatar