1. ## Pointer question.

Well, pointers are a big thing in C++, I understand them for the most part, but I'm lost on one thing:
Can you pass a pointer adress?

Like:

Code:
int a;
int *b;

b=a;

cout << &b;
If I'm not mistaken, that should return a's adress right? But then, how are pointers saved to memory if they have an adress that is exactly the same? That would confuse the computer. The only logical way I can see pointers working is:

Code:
int a=0;
int *b;

b=a; //Copy the contents of a to b's adress.

a=2; //Make a equal 2.
b ends up 1, a ends up 2. So am I correct in thinking that pointers are merely duplicates of a number, and, when changes, change both the "pointer" value and the actual value?

Or, am I off with this theory?

2. If I'm not mistaken, that should return a's adress right?
No. b is NOT a pointer to a but merly contains an address whose value is a. If you want to make a pointer to a, then do this:
Code:
b = &a;
That only increments b by sizeof(b) bytes, does nothing at all to a.

3. Code:
b = &a;
b++;
That would increment 'a' by one right?

And anyways, the code isint what I'm getting at. I'm wondering what this does:

Code:
b = &a;
cout << &b; //This should return a's adress ... right?
And above, I listed why that doesnt sound plausable... Or does the pointer actualy switch adresses with 'a'?

4. &b produces the address of b, not a. Try this and you will see the difference.
Code:
int a = 0;
int* b = &a;
cout << &b << endl;
cout << b << endl;

5. Originally Posted by Ancient Dragon
Code: