+ 2

What is the difference between call by pointer and call by reference in C++?

Suppose two functions is initialize like, int swap (int *a, int *b); int swap2(int &a, int &b); what is the difference between them. is in C call by call by reference and call by pointer are same? why in C++ they are different.

17th Jul 2017, 4:47 AM
Md Faizul Haque
Md Faizul Haque - avatar
1 Answer
+ 3
Accepting the references, you tell to client code that it must pass you valid objects. In case of pointers client code can pass nullptr or any other broken pointer. Also the difference in syntax inside swap functions.
17th Jul 2017, 6:07 AM
soman