Pass by reference pass by pointer

What is the difference between.

1
2
3
4
void gett(int *pointerr){

pointerr += 5;
}


and

1
2
3
4
void gett(int &referecee){

referencee +=5;
}


When would you choose to pass a variable by "REFERENCE" or by "POINTER".
Last edited on
In the one being passed by pointer, you're changing where the pointer points to instead of the data it points to.
Really, but it still doesnt answer my question.

if i rewrote it like this..

1
2
3
4
void gett(int *pointerr){

*pointerr +=5;
}


Than it does the same thing as the pass by reference right?
Last edited on
With the difference that the pointer might not be valid.
How would a pointer not be valid???

Thanks for your help by the way.
If the pointer points to non existant memory, protected memory, out of bounds memory, NULL, etc... the function will crash the application, or just cause corruption.
Last edited on
Ok, I was thinking that is what you ment, but I wasn't sure so I asked.
Thank You gcampton that helps alot.
Actually there is some history I believe in place here. Before C++ is invented, C programmers will use pointer to effect changes on the variables they intend to have before call and then after call a function. Then C++ came along and they introduce reference variables. Actually I would strongly recommend this way but in order to enable C code to run seam-lessly, C++ also accept the pointer notation from the C days.

Generally, for new C++ code I will use reference variables. It is only for legacy code maintenance or the API I am calling uses old C pointer notation would I use pointer variables.
Topic archived. No new replies allowed.