If you were to pass bar by value (no & or *), a copy of bar would be created. For larger bars, such as class types, this is a waste of time and space, but it means that the function cannot modify the original bar.
If you pass bar by pointer (with *), you have the benifit of not making a copy of bar (only the pointer gets copied), but your function will have to deal with awkward pointer syntax. Also, the function can modify the original bar.
Passing by reference (with &) is supposed to be the best of both worlds. You can't do it in C, only C++. You actually pass a pointer to bar, but it's behind the scenes. You use bar in your function just like you would if you had passed it by value, but it's not a copy of bar, so if you modify it, the original bar gets modified.
If you want to pass by reference to avoid copying bar, but want to ensure that your function doesn't modify bar, pass by constant reference, with const and &.
Passing by constant reference instead of passing by value saves time and space with objects that take up a lot of memory, but with little things like ints, just pass by value.
-
void foo(int bar); // By value
-
void foo(int* bar); // By pointer
-
void foo(int& bar); // By reference
-
void foo(const int& bar); // By constant reference.
-