# Thread: Pointers make sense

1. ## Pointers make sense

Reading pointers finally make sense and I just want to share and be told off if I'm wrong. It's all down to the names and the equals sign!
So,
& gives the reference,
* is the dereference.
These are inverse operators so applying both is like doing nothing. A lot like multiply by 2 and divide by 2 or add two and subtract 2. More formally, a/a = 1 and 1 + a - a = 1. So following on *& = 1.

Consider the snippet from Cprogramming.com pointers,

Code:
```int x;               // A normal integerint *p;              // An pointer to an integerp = &x;              // Assign the address of value x to p
cin >> x;            // Give x a value
cin.ignore();        // Remove the carriage return from the entry
cout << *p << "\n";  // This will print the value entered for x```
Now the bit that clicked for me was this,
Code:
`    p = &x`
so if I apply the * operator, I must apply to both sides
Code:
`    *p = *&x`
but the operators are inverses on the right hand side
Code:
`    *p = x`
the last line would act like
Code:
`cout << x << "\n";`
and it does.
Hopefully someone more practiced can say if this is a good schematic view. I've not seen this mentioned elsewhere and hope it helps someone who is stuck with pointers but thinks like a mathematician, got to be one or two out there.

2. Yes, I suppose that works. Just remember that & gives the address, not the reference (reference is an entirely different thing).

3. It seems that you are know learning about pointers.I am i student(i am learning too) so when i want to be sure about pointers and references i use a paper and a pencil.I draw small boxes that stand for memory cells.Then i draw arrows(from boxes that are hosting pointers) to point in other boxes.However because an image equals to 1000 words,see that
Code:
```int x=2;
int *p;
p=&x;```
Image(my intention was to upload one but it was too large)
Let adress of x to be 100

p x
+----+(space.)+--+
|100 |-------->| 2 |
+----+(space.)+--+

So if you follow this tactic then the most compilcated issues will be resolved easily

Popular pages Recent additions