Skip to main content
added 188 characters in body
Source Link
moonman239
  • 2.1k
  • 4
  • 20
  • 26

Ah! Something just came to mind - recursion. If a recursive function needs access to a variable, and you want the function to pass that variable to itself, then you want - and may need - a reference parameter. Otherwise, you're just allocating unnecessary memory - and may, in fact, cause a "stack overflow".

Edit: Some people have noted that pointers exist. Be that as it may, reference variables are sometimes preferable simply because they render referencing and dereferencing unnecessary.

Ah! Something just came to mind - recursion. If a recursive function needs access to a variable, and you want the function to pass that variable to itself, then you want - and may need - a reference parameter. Otherwise, you're just allocating unnecessary memory - and may, in fact, cause a "stack overflow".

Ah! Something just came to mind - recursion. If a recursive function needs access to a variable, and you want the function to pass that variable to itself, then you want - and may need - a reference parameter. Otherwise, you're just allocating unnecessary memory - and may, in fact, cause a "stack overflow".

Edit: Some people have noted that pointers exist. Be that as it may, reference variables are sometimes preferable simply because they render referencing and dereferencing unnecessary.

Source Link
moonman239
  • 2.1k
  • 4
  • 20
  • 26

Ah! Something just came to mind - recursion. If a recursive function needs access to a variable, and you want the function to pass that variable to itself, then you want - and may need - a reference parameter. Otherwise, you're just allocating unnecessary memory - and may, in fact, cause a "stack overflow".