Q&A

Q1:Why should I declare an object as const if it limits what I can do with it?
A1: As a programmer, you want to enlist the compiler in helping you find bugs. One serious bug that is difficult to find is a function that changes an object in ways that aren't obvious to the calling function. Declaring an object const prevents such changes.
Q2:Why should I bother to declare anything on the heap?
A2: Objects on the heap persist after the return of a function. In addition, objects declared on the heap can be used to create complex data structures as explored in Hour 19, “Linked Lists.”

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.