11.07.2015 Views

tYSR20

tYSR20

tYSR20

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 8Taking a First Look at C++ PointersIn This Chapter Addressing variables in memory Declaring and using pointer variables Recognizing the inherent dangers of pointers Passing pointers to functions Allocating objects off the heap (whatever that is)So far, the C++ language has been fairly conventional compared with otherprogramming languages. Sure, some computer languages lack (il-)logicaloperators (see Chapter 4 for more) and C++ has its own unique symbols, butthere’s nothing new in the way of concepts. C++ really separates itself from thecrowd in definition and use of pointer variables. A pointer is a variable that“points at” other variables. I realize that’s a circular argument, but let me putit this way: A pointer variable contains the address of a variable in memory.This chapter introduces the pointer variable type. It begins with some conceptdefinitions, flows through pointer syntax, and then introduces some ofthe reasons for the pointer mania that grips the C++ programming world.Variable SizeMy weight goes up and down all the time, but here I’m really referring to thesize of a variable, not my own variable size. Memory is measured in bytes orbits. The following program gives you the size of the different variable types:// VariableSize - output the size of each type of// variable#include #include #include using namespace std;int main(int nNumberofArgs, char* pszArgs[])

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!