C Pointers. Confuse ?

When I started learning programming with C++, the learning is stopped when the chapter is reached to pointers. Pointers are often a bit of a stumbling block for people who want to learn C/C++. I read some articles about pointers, but most of them can’t explain the confusing point of pointers for me. In this article, I won’t explain basic and advance usage of pointers. I will explain what I was confused about pointers and what is need to know to clear on pointers. 

What is a Pointer

We can assume pointer is just like other datatypes, but it holds memory addresses rather than values. So, a pointer is a variable that contains a memory address. Please carefully look at the codes below.

int d = 13;
int *e = &d;
printf("d value is %i \n", d); //13
printf("&d value is %p \n", &d); //0xbfffdca8 memory address
printf("e value is %p \n", e); //0xbfffdca8 memory address
printf("*p value is %i \n", *e); //13

Line 1 initiate the value 13 to d.

Line 2, the memory address of d(&d) something will look like 0xbfffdca8 is assigned to *e that is integer pointer type. Still there is no problem. Using pointer is like using normal datatypes. Then, I printed the variables d, e and *e.

Confuse ??

Confusing start here. We assign the address value &d to pointer *e ( can assume like this, int *e = 0xbfffdca8 ), but when we accessing and print *e ,the output is value of d (13) instead of the address. Although we can assume pointers are like normal data types, we also have to assume initialising and accessing ways in pointers are different from normal datatypes.

Although we assigned the memory address to *e, the whole *e is not holding the memory address. Pointer name e is holding the address and ‘*‘ sign is pointing to real value on that address. So *e is printed 13 and e printed 0xbfffdca8.

That is what I was confused in recent years. If you have the same problems on pointers, I hope you are now ok. Then you can now find and practice pointer exercises. Here is one of the good tutorials about pointers. 

http://www.thegeekstuff.com/2011/12/c-pointers-fundamentals/

http://www.thegeekstuff.com/2012/01/advanced-c-pointers/

2 thoughts on “C Pointers. Confuse ?

Leave a Reply

Your email address will not be published. Required fields are marked *