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 8: Taking a First Look at C++ Pointers 111be somewhere else in memory entirely — only the computer knows for sureand only at the time that the program is executed.This is somewhat analogous to a hotel. When you make your reservation, youmay be assigned room 0x100. (I know that suite numbers are normally notexpressed in hexadecimal, but bear with me.) Your buddy may be assigned80 doors down in room 0x180. Each variable is assigned an address when itis created (more on that later in this chapter when we talk about scope).Address OperatorsThe two pointer-related operators are shown in Table 8-1. The & operatorsays “tell me your hotel address,” and * says “his address is.”Table 8-1Pointer OperatorsOperatorMeaning& (unary)The address of* (unary) (In an expression) the thing pointed at by* (unary) (In a declaration) pointer toThe following Layout program demonstrates how the & operator displays thelayout of memory variables in memory:// Layout - this program tries to give the// reader an idea of the layout of// local memory in her compiler#include #include #include using namespace std;int main(int nNumberofArgs, char* pszArgs[]){int end;int n;long l;float f;double d;// set output to hex modecout.setf(ios::hex);cout.unsetf(ios::dec);

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

Saved successfully!

Ooh no, something went wrong!