liveBook · Manning

Chapter 11: Pointers

What you will learn in chapter 11 of Modern C, Third Edition

The chapter introduces pointers as references to other objects and shows how they let a function change objects belonging to its caller.

After this chapter you will be able to

What it builds on

Section by section

Introduction

The chapter introduces pointers as references to other objects and shows how they let a function change objects belonging to its caller.

Key terms: pointer, referenced type, pointed-to object, double_swap, caller, pure function

11.1 Pointer operations

This section previews the pointer operations and states explained in the following subsections.

11.1.1 Address-of and object-of operators

This subsection shows how address-of and object-of operators let a function access a caller’s objects through pointers, and warns against dereferencing null or invalid pointers.

Key terms: address-of operator, object-of operator, address, pointer, pointer type, dereferences, declaration, expression, invalid pointer, null pointer

11.1.2 Pointer addition

This section explains how pointer addition accesses and traverses array elements, while distinguishing a pointer from an array object.

Key terms: valid pointer, reference type, pointer addition, a+len, aStop, array object, pointer, sizeof, array notation, len

11.1.3 Pointer subtraction and difference

This section explains subtracting an integer from a pointer, finding the distance between pointers in the same array, and using the appropriate types and format for those results.

Key terms: pointer arithmetic, subtract an integer from a pointer, pointer difference, same array object, ptrdiff_t, <stddef.h>, size_t, %p, void*

11.1.4 Pointer validity

This section explains how to keep pointer values valid, why a pointed-to object’s type matters, and how array bounds limit both pointer arithmetic and dereferencing.

Key terms: pointer variables, null, truth value, valid object, representation, non-value representation, designated type, dereferenced, array bounds, one element beyond

11.1.5 Null pointers

The section distinguishes null pointer values from null pointer constants and explains why it recommends nullptr instead of NULL.

Key terms: null pointer, null pointer constant, compile-time constant, const-qualified object, NULL, nullptr

11.2 Pointers and structures

This section explains how to access structures through pointers, use pointer-based functions safely, and design interfaces that expose or hide structure definitions.

Key terms: pointer to structure, -> operator, member, object, pointer argument, null, validity, compose, opaque structures, interface

11.3 Pointers and arrays

The section introduces two facts that make arrays and pointers closely related in C, while noting that their convenience can confuse beginners.

Key terms: pointer and array element access, array parameters, pointers

11.3.1 Array and pointer access are the same

This subsection explains why indexed access works for both arrays and pointers, and how array-to-pointer decay makes the equivalence possible for arrays.

Key terms: A[i], *(A+i), array access, null, array-to-pointer decay, array decay, &A[0], array values

11.3.2 Array and pointer parameters are the same

This section explains how C treats array parameters as pointers, how that rule applies to multidimensional arrays, and what programmers must do to describe and validate array sizes.

Key terms: decay, array parameter, pointer, innermost dimension, pointer to an array, two-dimensional arrays, length parameters, array notation, VLAs, conventional indexing

11.4 Function pointers

This section explains how function pointers work and how they enable generic library operations and dynamically chosen function calls.

Key terms: function decay, function pointer, function call operator, bsearch, qsort, array base, void pointer, compare, comparison function, INT_MAX

11.5 Summary

Where this is used later

Concepts explained in this chapter

← Chapter 10: Organization and documentation Chapter 12: The C memory model →

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.