0

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?

BobbyT432
  • 51
  • 6

1 Answers1

0

Your first example passes by pointer, not reference.

The second example void foo(int &num) is a function that takes its argument by reference.

Jesper Juhl
  • 30,449
  • 3
  • 47
  • 70