liveBook · Manning

Address-of operator

As explained in Modern C, Third Edition

The address-of operator is the C unary operator that obtains a pointer to an object or function designated by its operand.

Passing an object’s address

A call such as double_swap(&d0, &d1) passes the addresses of d0 and d1. The pointer parameters p0 and p1 then identify those objects, so *p0 and *p1 access and modify their contents. section 11.1.1

double_swap(&d0, &d1);

Inspect the compact call that applies the address-of operator to both swap operands. section 11.1.1

The unary address-of operator & produces a pointer type. Its operand designates an object whose address can be passed elsewhere; the receiving function need not know the object’s original variable name. The unary * operator reverses this access by dereferencing the pointer. In a declaration, * creates pointer type syntax; in an expression, it accesses the pointed-to object. section 11.1.1

TAKEAWAY rules:

  • Use & to pass an object’s address to a pointer parameter. section 11.1.1
  • Do not dereference a null or invalid pointer; execution using * with either fails. section 11.1.1
  • Recognize that equal addresses can create aliasing, allowing one pointer-based assignment to change the object accessed through another pointer. section 12.3

How Modern C, Third Edition covers it

How deep it goes
Explains unary syntax, pointer results, inverse dereferencing, * notation, and null or invalid-pointer failure.
Examples
Uses double_swap calls and pointer-parameter functions, then contrasts aliasing with blub(&c, &c).
What it assumes
Assumes pointer notation and pointer validity distinctions while explaining address-taking through a concrete swap.
What you can do after
Apply it to pass object addresses into pointer parameters and enable indirect modification.
How it connects
Connects pointers, dereferencing, aliasing, and the C memory model.

Also explained in

Compare how 2 books explain address-of operator →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Modern C, Third Edition. The section links point to the parts of the book it draws on.