getting confused with dereference n pointers

Helo pls i am having a serious headache with pointers and dereference operator. if explain with example will be appreciated.
1
2
3
4
5
6
7
8
9
10
11
int i = 8 ; // i is an int
int* pi = 0 ; // pi is a pointer to int

pi = &i ; // unary & is the 'address of' operator
// &i yields the address of i and pi now 'points' to i

*pi ; // unary * is the dereference operator
// *pi yields an alias for (a reference to) the int pointed to by pi

*pi = 9 ; // assign 9 to the int pointed to by pi
// ie. assign 9 to i (because pi points to i) 

pointers point to places in memory and are moved along the memory by adding a value which is the number if times it is moving along the memory.
so if you have an array of all odd numbers and say
mypointer = odd[0]
std::cout << mypointer;
the output is 3
now add one to my pointer
mypointer++;
then do
std::cout << mypointer;
the output is 5
as you can see the number output is not 4 but 5 which is the value of the memory after odd[0] which is the 1st odd number. the value of mypointer is = to odd[1].
Thanks guys am really grateful
Topic archived. No new replies allowed.