*val - a pointer (memory address) &val - a reference (also a memory address)
For most purposes, these two are the same.
However, if you have a function that takes a pointer like testFunc(int *val), every time you pass a pointer to it you make a copy of the pointer. You can change the passed pointer without changing the original.
A function that takes a reference, like testFunc(int &val), doesn't make a copy of the value, so if you change that reference you will also change the original reference.
There are also some fundamental differences in the way C++ treats pointers and references, but I assume you aren't that interested in them for the purpose of this question.
Apart from 2 or 3 lectures for c in college I have never done anything with c/c++, but thanks for explaining. I'll check out the beginner's guide when i have some time.
2
u/SgtBlackScorp Aug 24 '17
I'm actually interested in what exactly the difference between *val and &val is. Could you elaborate?