Help with Documentation translation

Hi, I was just trying to understand the dereference operator portion of http://www.cplusplus.com/doc/tutorial/pointers/ and was wondering if translating it to this would still be true:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// andy the homewrecker.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
using namespace 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.
Last edited on
closed account (zb0S216C)
De-referencing is simple to understand:

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.

Wazzak
Topic archived. No new replies allowed.