As an example I know that
void foo(int *num)
{
num++;
}
foo(&num);
will pass num
by reference. However, why do people use
void foo(int &num)
{
num++;
}
I've heard that you should use that syntax over what I posted above, why is this?
As an example I know that
void foo(int *num)
{
num++;
}
foo(&num);
will pass num
by reference. However, why do people use
void foo(int &num)
{
num++;
}
I've heard that you should use that syntax over what I posted above, why is this?
Your first example passes by pointer, not reference.
The second example void foo(int &num)
is a function that takes its argument by reference.