< Previous | Contents | Next >

Pointers: Tic-Tac-Toe 2.0


Pointers are a powerful part of C++. In some ways, they behave like iterators from the STL. Often, you can use them in place of references. But pointers offer functionality that no other part of the language can. In this chapter, youll learn the basic mechanics of pointers and get an idea of what theyre good for. Specifically, youll learn to:

n Declare and initialize pointers

n Dereference pointers

n Use constants and pointers

n Pass and return pointers

n Work with pointers and arrays


 

Understanding Pointer BasicsIntroducing the Pointing ProgramDeclaring PointersInitializing PointersAssigning Addresses to PointersDereferencing PointersReassigning PointersUsing Pointers to ObjectsUnderstanding Pointers and ConstantsUsing a Constant PointerUsing a Pointer to a ConstantUsing a Constant Pointer to a ConstantSummarizing Constants and PointersPassing PointersIntroducing the Swap Pointer Version ProgramPassing by ValuePassing a Constant PointerReturning PointersIntroducing the Inventory Pointer ProgramReturning a PointerUsing a Returned Pointer to Display a ValueAssigning a Returned Pointer to a PointerAssigning to a Variable the Value Pointed to by a Returned PointerAltering an Object through a Returned PointerUnderstanding the Relationship between Pointers and ArraysIntroducing the Array Passer ProgramUsing an Array Name as a Constant PointerPassing and Returning ArraysIntroducing the Tic-Tac-Toe 2.0 GameSummaryQuestions and AnswersDiscussion QuestionsExercises