// andy the homewrecker.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
usingnamespace std;
int _tmain(int argc, _TCHAR* argv[])
{
int andy = 25;
int * andysHouse = &andy;
cout << "Andy is " << andy << endl;
cout << "Andy lives at " << andysHouse << endl;
cout << "The address of andy's house is " << andysHouse << endl;
cout << "Andy's house contains andy who is " << *andysHouse << endl;
cin.get();
return 0;
}
For me, picturing andy inside of a house rather than inside of ted is a little easier to imagine (and slightly less....rainbowish(not that there's anything wrong with that)) Just wanted to make sure I'm getting the translation right.
When you de-reference a pointer, you're basically saying this: "Pointer, what are you pointing to?" De-referencing yields the value of the location to which it points.
Hydrasin wrote:
cout << "The address of andy's house is " << andysHouse << endl;
Here, andysHouse evaluates to the address of andy.
Hydrasin wrote:
For me, picturing andy inside of a house rather than inside of ted is a little easier to imagine
That's the best thing to do. Pointers are simple, but some find them difficult. By analogising pointers, it becomes simpler.