# Me need help wit pointers, me dum dum

• 10-09-2001
Estauns
Me need help wit pointers, me dum dum
Hey all,

Can anyone give me a hand with theory behind pointers? I just don't understand them for the life of me. What is the purpose of them, what use do they have?

The only thing I could come up with while reading tutorials and trying to understand them was that they give you an instance of a variable without actually updating the variable... lol thats so whacked, I basically mean this..

You have Pointer A and Variable B. Variable B is set at 30, so Pointer A is set at 30. When you change Variable B to say, 29, Pointer A automatically adjusts itself to 29 as well. But I don't see much reason to that either, whats the point? You could just use Variable B and check that, rather then using a pointer.

Thanks a tonne,
-Estauns
• 10-09-2001
sean
Pointers are usually used to literlly point to another object in memory. What most people do, is use the following line of code to initialize their pointer:

data_type *pointer_name = &variable_name[1];

If you;re doing a teach-yourself course, don't follow their examples, because you're never going to need a point to "7", and that's why your confused. What you will need to do, is somehow pass an entire array to a function as a parameter (if you haven't learned about function paraeters yet, just keep a link to this reply or something. Instead of passing the entire array to the function, which is either impossible or impractical, depnding on how you do it. But if you set the pointe to the address of (the reason for the &) the first element in the array, then you can just pass that. Once inside the function: You can declare a new array to represent the original array inside the function. Getting the data into this new array is done this way:

data_type array_name[size];
// make a loop so that the following is repeated the same nmber of times as there are slots in your array, each time, have the variable i go up 1.
array_name[i] = *pointer_name;
pointer_name++;
// Incrementing the pointer by 1, will set it to the next address, which will be the next slot in the array. You can either do it with a loop, or keep going until the data contained in the current slot is null. If you have other question, my email address is at the bottom.

Sean Mackrory
sean_mackrory@hotmail.com
• 10-09-2001
Salem
This is one of the better explanations of pointers I've found
http://pweb.netcom.com/~tjensen/ptr/pointers.htm
• 10-09-2001
Hannwaas
To put it short:
a variable contains a value.
a pointer contains a memory adress.
using the * operator on the pointer allows you to access the value at its memory location.
• 10-09-2001
Brown Drake
You wouldn't normally use pointers in the types of cases usually given in textbooks introducing them. Their main purpose that I've seen is to refer to large data structures with a small data structure (the pointer).