8.1 Memory Addresses


8.1 Memory Addresses

It was mentioned in Chapter 6 how variables and constants are data, and data is stored in a computer's memory much like letters are slotted into mailboxes or like files are arranged in the drawers of a filing cabinet. Each slot or area of memory has a specific and unique address called a memory address. As a program is executed it is allocated a finite pool of memory by the operating system to store whatever variable and constant data it declares. Since data varies, the amount of memory needed to store, say, an integer variable differs from the amount needed to store a Boolean. Regardless, each of them still has a unique location in memory (their memory address). The memory size in bytes of any variable or data type can be found out by using the sizeof function, as shown below:

      int size_of_integer = sizeof (int);      int size_of_boolean = sizeof (bool); 
Note 

Functions are examined in Chapter 9.

Generally, when a programmer references a variable or constant, it is by using the variable or constant name, such as "int Number"-here, Number is the variable name. However, though the importance might not yet be apparent, it is sometimes useful to know and use the actual memory address of a variable or constant. For this reason, we must now explore pointers.




Introduction to Game Programming with C++
Introduction to Game Programming with C++ (Wordware Game Developers Library)
ISBN: 1598220322
EAN: 2147483647
Year: 2007
Pages: 225
Authors: Alan Thorn

Similar book on Amazon
Beginning C++ Through Game Programming
Beginning C++ Through Game Programming
Beginning Game Programming
Beginning Game Programming
The Ultimate Guide to Video Game Writing and Design
The Ultimate Guide to Video Game Writing and Design

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net