As a general rule, use references in function parameters and return
types to define attractive interfaces. Use pointers to implement
algorithms and data structures.
I read this line in an article.I had the doubt of why reference cannot be used in algorithms and datastructures?
Please help me undestand why is it.
Because a reference can’t be made to refer to any other object after it’s been initialised to refer to a particular one.
As proof, §8.5.3.2 of the Standard says
Data structures and algorithms (though to a lesser extent) usually involve adding, removing, and reordering objects within themselves. With references you cannot do this, so you use pointers to do it inexpensively.