7Pointers and Memory Management

This chapter is dedicated to the notions of pointers and references, already mentioned in Chapter 4, with illustrations mostly written in C and C++. These languages include explicit pointers, which sometimes reveal technical details closely linked to computer architecture. Pointers and references are essential to the notion of objects, which will be discussed in greater detail in the context of object-oriented languages (Volume 2, Chapters 3 and 4) in relation to Java (see Volume 2, section 4.1), Python (see Volume 2, section 4.4) and C++ (see Volume 2, section 4.2).

7.1. Addresses and pointers

In terms of low-level implementation, a computer memory may be seen as a large “array” of bytes. This “array” is made up of zones corresponding to program variables and, more generally, of zones explicitly or silently allocated by the program. Some of these zones are created automatically by the program’s execution mechanisms, some by compilation mechanisms and some by demands formulated explicitly in the source code. The information manipulated by a program is stored in the memory at a certain location, indicated by an address: this notion has already been discussed in Chapters 2 and 4. An address may thus be seen as the index in the memory “array” where an item of information is stored.

An address is an element of information like any other: it may be recorded, manipulated or used to read or write at the location it denotes. A value of the address type ...

Get Concepts and Semantics of Programming Languages 1 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.