16

Arrays, Pointers, and References

Caveat emptor!

– Good advice

This chapter describes the lower-level notions of arrays and pointers. We consider the uses of pointers, such as array traversal and address arithmetic, and the problems arising from such use. We also present the widely used C-style string; that is, a zero-terminated array of chars. Pointers and arrays are key to the implementation of types that save us from error-prone uses of pointers, such as vector, string, span, not_null, unique_ptr, and shared_ptr. As an example, we show a few ways we can implement a function that determines whether a sequence of characters represents a palindrome.

§16.1 Arrays

Pointer arithmetic

§16.2 Pointers and references

Pointer and reference parameters ...

Get Programming: Principles and Practice Using C++, 3rd 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.