9

Pointers and References

LEARNING OBJECTIVES

At the end of the chapter, you should be able to understand and use

  • Pointers and references, and know when to use what?

  • Objects and pointers.

  • Objects and references.

  • Dangling pointers and memory leaks.

  • Constant pointers, constant objects and references.

9.1 Introduction

In our experience of teaching C++, we found that learners are pretty confused about pointers and references and related memory management. This is mainly because they would have probably picked up the “what” of pointers and references and not the “why” of pointers and references. In this chapter, we would like to bring out special characteristics of pointers and references like

  • Pointers are just like any other variables.
  • Pointers ...

Get Object-oriented Programming Using C++ and Java 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.