This question has already been answered:
#include <iostream> using namespace std; void display_ptr(int *ptrint) { cout << *ptrint << endl; } void display_addr(int &toint) { cout << toint << endl; } int main() { int i{ 10 }; display_ptr(&i); display_addr(i); }
In this example, the possibilities of a construction with a pointer are not clear to me, compared to passing a value by reference.
As you can see, to use a pointer value, you need to get it using *
, and also pass in an argument using &
.
Using the transmission by reference, nothing is needed except the indication in the parameter itself, while the value is also not copied and can also be changed by reference.
I do not quite understand what profit pointers have if it is much more convenient to pass the value by reference.