Just call myFunction (myVar). The compiler then will pass your variable by reference, which means, that if you change that variable in a function, this variable will be changed outside of a function as well.
As for the difference between * and &.
If you have a variable of some type (let it be int) and you want to get its pointer, you can apply get the address using the operator &:
int i;
int* pointer_to_i = &i;
If your function takes int*, you then need to pass either &i or pointer_to_i (they are obviously the same thing). If your function takes int or int&, then you should pass just i.
A function taking its argument by value (like void f(int);) deals with the copy of its argument. All the changes this function makes to this argument are not visible outside. If a function takes its argument by either pointer or reference, all the changes made to the argument are visible outside.
When you get a pointer as an argument, you need to:
- Check that it is not
NULL in C or nullptr in C++
- Dereference it. That is, you should write
*i = 0 to put zero into the memory pointed to by i.
Other than that, passing by pointer (like void f(int*){…}) or by reference (like void f(int&){…}) effectively differs only in syntax and has the same meaning.
Pointers can point nowhere and can be made to point to another value. References on the contrary always point to something and always point to the same memory location.
That's in brief. But you should really read some decent C++ book, there are many tricky cases with references or pointers.
And, finally, a mnemonic rule.
int i; //< that's a plain number
int* pi = &i; //< that's a pointer to int
int (*pi_2) = &i; //< the same pointer to int
int j = *pi_2; //< here *pi_2 is again an int just as above
That said, this asterisk indicating a pointer can be prepended to a variable, thus 'stripping' one indirection level from its type. The explanation is not quite correct formally, but sometimes handy to understand what happens.