# Good pointer learning tool?

• 03-11-2009
Devolution
Good pointer learning tool?
Hey, I don't have any specific coding question, but I am having a lot of trouble with pointers in my class and was wondering if anyone knows of a good tool or website to help learn. I've been rummaging around other websites but it isn't really "clicking" for me. I feel like I am falling behind but my professor's office hours are during another class. Any hints or tips pertaining to pointers would be more than welcome as well.

I do know that pointers' contents are just addresses of other variables, but I'm having a lot of trouble knowing how and when to use them as parameters with their symbols (*, &).

• 03-11-2009
MK27
Linked lists (if you can). Find a linked list tutorial and try and write a basic program to add, remove, and show all nodes.
• 03-11-2009
Elysia
A small guide:
int x = 10;
int* p = &x;
*p = 20;
After this, x is 20, and *p is 20.
Before, x is 10.
• 03-11-2009
baccardi
the best way to understand pointers is to study a little bit of assembly language
• 03-11-2009
vart
Quote:

Originally Posted by baccardi
the best way to understand pointers is to study a little bit of assembly language

makes no sence for me
• 03-11-2009
baccardi
so i guess you haven't studied it, because programming with assembly involves computer architecture knowledge which is very good in understanding how really pointers work
• 03-11-2009
vart
Quote:

Originally Posted by baccardi
so i guess you haven't studied it, because programming with assembly involves computer architecture knowledge which is very good in understanding how really pointers work

you guessed wrong
• 03-11-2009
zacs7
> so i guess you haven't studied it, because programming with assembly involves computer architecture knowledge which is very good in understanding how really pointers work
I disagree. Looking at how one implementation works is by no means a good way to learn how they work overall. Not to mention there is usually no concept of "pointers" at such a low-level.

That's like learning how to drive by looking at how the steering column in your car works.
• 03-11-2009
BEN10
in c '&' is the address of operator which gives the address where the variable in memory is stored.'*' is the value at address operator.it means if you use '*' and '&' with a variable it will give you the variable's value.
for eg.
Code:

```int i=10; printf("%u %d",&i,*(&i));```
this will output the address and the value of i(which is 10).
Now this means that if you want to have access to the address of the variable you can use these operators.and once you have access to any variable's address you can change it to other value or can do some operations upon it.thus if you want to change the value of a variable or do some advanced operations you need to pass the address of the variable.
• 03-12-2009
whiteflags
Quote:

Originally Posted by Elysia
A small guide:
int x = 10;
int* p = &x;
*p = 20;
After this, x is 20, and *p is 20.
Before, x is 10.

int * q;
q = p;
This is pointer assignment for pointers with the same level of indirection, since we're copying the value of p (some address), not p's address.
++(*q);
*q++;
Know the syntax for your increments and decrements.
• 03-12-2009
laserlight
Quote:

Originally Posted by whiteflag
Know the syntax for your increments and decrements.

Building on whiteflag's examples, find out the difference (if any) between ++*q, ++(*q), *q++ and (*q)++.
• 03-12-2009
pic-o-matic
This is really cool, when you can follow this guy you will be the pointer master :). I followed a lesson or 4 or so, and found it really "clearing up the mist". If i find some more time i'm going to watch the whole "show"

B.t.w. i think i found the link on this forum, somewhere...
• 03-12-2009
Snafuist
I have to see some formal stuff in order to understand things, and the following helped me a lot to understand pointers:

A variable is a 4-tuple consisting of name, size, address and value.
A pointer is a variable whose value is the address of another variable.

For C, this is almost true. On the other hand, you don't need to fully grasp the concept of pointers right at the beginning. Read through the pointer chapter of whatever book you are using to learn C, but don't try to understand everything. When you're actually dealing with pointers (writing a linked list is the common example), stick to syntactical rules. When you're used to the syntax, read the chapter again.

Pointers are so difficult because the first time you hear about them, you probably don't have the slightest clue about their usefulness. First find out why they are useful and how to use them syntactically, then try to understand them.

Greets,
Philip