Book contents
- Frontmatter
- Contents
- Acknowledgments
- Dedication
- 1 Introduction
- 2 From Source File to Executable File
- 3 Variables and Objects; Pointers and Addresses
- 4 Dynamic Allocation and Deallocation of Memory
- 5 Functions and Function Calls
- 6 One-Dimensional Arrays and Strings
- 7 Multi-Dimensional Arrays
- 8 Classes and Objects
- 9 Linked Data Structures
- 10 Memory Leaks and Their Debugging
- 11 Programs in Execution: Processes and Threads
- A Hanoi Towers Puzzle
- B Tracing Objects in C++
- C Tracing Objects and Memory in C++
- D Thread-Safe and Process - Safe Reporting and Logging Functions
- Glossary
- Index
3 - Variables and Objects; Pointers and Addresses
Published online by Cambridge University Press: 13 January 2010
- Frontmatter
- Contents
- Acknowledgments
- Dedication
- 1 Introduction
- 2 From Source File to Executable File
- 3 Variables and Objects; Pointers and Addresses
- 4 Dynamic Allocation and Deallocation of Memory
- 5 Functions and Function Calls
- 6 One-Dimensional Arrays and Strings
- 7 Multi-Dimensional Arrays
- 8 Classes and Objects
- 9 Linked Data Structures
- 10 Memory Leaks and Their Debugging
- 11 Programs in Execution: Processes and Threads
- A Hanoi Towers Puzzle
- B Tracing Objects in C++
- C Tracing Objects and Memory in C++
- D Thread-Safe and Process - Safe Reporting and Logging Functions
- Glossary
- Index
Summary
Variables as “data containers” with names. Values as data - simple (innate or elementary) data, structures, and objects. Referencing variables through pointers. Unnamed “data containers” and their referencing through pointers. The dual role of pointers as address holders and binary code “interpreters”. Various interpretations of the contents of a piece of memory. Pointer arithmetic. Why C/C++ cannot be interpreted in a platform-free manner like Java can. Why C/C++ cannot have a garbage collector.
During the execution of a program, a variable of the program corresponds to a location in memory, and the address of that location replaces all symbolic references to the variable in the load module. This is one of the important facts touched upon in Chapter 2 when we discussed why we can behave as if the program in its source form executes in the memory. In this chapter we will refine this notion and discuss its consequences.
The idea of variable as “data container” is very natural. In its crudest form we can imagine a variable to be a box, and whatever is in the box is the value of that variable. If we want to evaluate the variable (i.e., find its value), all we need do is look in the box and see what is in there; when we want to store something in the variable, we simply put it into the box. In fact, this crude notion is not that far from reality.
- Type
- Chapter
- Information
- Memory as a Programming Concept in C and C++ , pp. 21 - 44Publisher: Cambridge University PressPrint publication year: 2003