Chapter 11. Pointers


This chapter introduces a subject that is closely related to arrays. As you learned in the previous chapter, an array is a method for creating a block of memory that contains data. A pointer is another, more powerful way of doing the same thing.

When your program declares a variable, it asks the operating system for some memory. The program uses that memory to store data. For instance, if your program declares an integer variable, it gets enough memory from the operating system to store an integer. Programmers call this process memory allocation.

In addition to allocating memory for data, your programs can allocate memory for pointers to data. A pointer does not contain data; instead, it contains the address of data. Every location in memory has a unique address. When your program creates a pointer, it creates a variable that contains an address of a location in memory.

As you'll see throughout the remaining chapters of this book, games use pointers a lot. The ability to create a pointer is an extremely powerful programming tool. It will also be the source of most of your programming errors. If you want to write games, you must learn to use pointersand use them well.



Creating Games in C++(c) A Step-by-Step Guide
Creating Games in C++: A Step-by-Step Guide
ISBN: 0735714347
EAN: 2147483647
Year: N/A
Pages: 148

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