Q&A

Q1:Why use references if pointers can do everything references can?
A1: References are easier to use and understand. The indirection is hidden, and there is no need to repeatedly dereference the variable.
Q2:Why use pointers if references are easier?
A2: References cannot be null, and they cannot be reassigned. Pointers offer greater flexibility, but are slightly more difficult to use.

Get Sams Teach Yourself C++ in 24 Hours, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.