Passing by reference vs. Pointing to data?

When i am writing functions that require the original address/variable i always end up using reference. It seems like a much easier form of modifying data opposed to pointing to data, the only way i use pointers at the moment is when i am allocating memory dynamically. When will i come across situations where reference just does not cut it and i am forced to use variables? Im guessing when i get into higher forms of c++ such as linked lists/advanced class modification? Just curious.
A pointer parameter can be received as null, allowing you to pass nothing, if need be.
Additionally, you can change what a pointer points to if you like.
closed account (4z0M4iN6)
Need4Sleep wrote:
When will i come across situations where reference just does not cut it and i am forced to use variables?

Seems to depend much on your kismet. I can't guess it.


Use references in function parameters and return types to define attractive interfaces.

Use pointers to implement algorithms and data structures.

Some differences :


A pointer can be re-assigned any number of times while a reference can not be reassigned after initialization.

A pointer can point to NULL while reference can never point to NULL

You can't take the address of a reference like you can with pointers

There's no "reference arithmetics"
Topic archived. No new replies allowed.