# Thread: "Pointers" <-- crappy name

1. Originally Posted by argv
what if I said "wheres minnesota?" Just kidding, but really, my point is (no pun intended) that for a beginner who knows nothing about the concept of passing information by value or by address, I would think a simple explaination that a "pointer" is nothing more than the address where a variable is stored. That makes sense to me, but so many books and 'tutorials' and whatever do a horrible job of explaining what a pointer is. They try to show you code, etc etc..
I've tried using an explanation similar to yours. It doesn't help much. The question is not what a pointer IS (most people can understand that part) but why you would need one.

And there's nothing special about hexadecimal. An address is an address, whether you express it in binary, decimal, hex, or encode it into a sonata using no instances of the musical note 'E'

2. Originally Posted by argv
Mostly I just think alot of confusion from beginning people (like myself) is the term "pointers" because.. really.. does it "point" to anything, or is just an address send to a function to tell that function where to store it's value?
The last phrase is correct, but the "or is" is sort of non-sensical, like "is the sky really blue, or is it just the color of oxygen in the atmosphere?". The sky is blue, the color of oxygen in the atmosphere. A pointer is an address sent to a function that points to where a value is stored.

Going back to the street metaphor, and the Original Post, a map would be something of an area. If I wrote "123 Elm St." down on a piece of paper and gave it to you, you would not call it a map. And in fact map is a term in programming you will discover later, and it involves regions of memory.

Some (non-compiled) languages use something called a reference which is functionally identical to a pointer. The only word I have heard that might be more descriptive than "pointer" is "reference". On the other hand, pointer is a more unique word than "reference" -- it is not so overloaded semantically. So once you get the concept, pointer is probably more convenient, immediately recognizable, and less likely to be confused with something else. Maybe "referer" would be good if you do not have to say it five times fast

That makes sense to me, but so many books and 'tutorials' and whatever do a horrible job of explaining what a pointer is.
I agree 100% on that. But it is not because of the name; it is because of the strong elliptical tradition in programming "instructional" discourse, which is virtually the de facto standard. You could call it anything, it will not improve the quality of the material to which you refer.

Originally Posted by brewbuck
The question is not what a pointer IS (most people can understand that part) but why you would need one.
Bravo brewbuck. That's the rub.

3. Originally Posted by MK27
Some (non-compiled) languages use something called a reference which is functionally identical to a pointer. The only word I have heard that might be more descriptive than "pointer" is "reference". On the other hand, pointer is a more unique word than "reference" -- it is not so overloaded semantically. So once you get the concept, pointer is probably more convenient, immediately recognizable, and less likely to be confused with something else.
Reference is the concept, pointer is the implementation. The fact that a pointer is an address enables a lot of syntax you wouldn't have otherwise -- subtraction of pointers, incrementing and decrementing, testing for NULL, etc.

References I think are more confusing, because often they automagically dereference themselves, which is hard to explain. And they need not be implemented in terms of addresses, so it's difficult to talk about what a reference is actually "made of" other than saying it's just some sort of magic object that stands for some other object.

People have trouble with abstraction. Some people can't even grasp why functions are important. I'm not surprised that a lot of people can't figure out pointers, but what bothers me is the claim that pointers are intrinsically difficult to understand.

They aren't. What's hard to understand is why on Earth you'd need one.

4. ## ...

Originally Posted by laserlight
Reasonably concise explanation, except that:
• Hexadecimal is just a common representation for addresses so you should leave it out or comment as such.
• You assume that the reader knows the context with which you talk about the address of and indirection operators.
• You say nothing about pointer arithmetic and one past the end pointers.
• You say nothing about null pointers and null pointer constants.
No I did not. My main point really, is that most explainations of pointers really suck. The concept is not hard to get, I guess it's just who gives it to you. I'm very glad that I have a good teacher who does a really good job of explaining and driving home the concept.

Still, I maintain that, from my understanding at least, it all boils down to the fact that a "pointer" is simply an address. Like if you wanna find someones house.. you use their address.. if you want to store a value created by another function, you use it's address. That just seems, to me, a better approach to the understanding of pointers.. but, maybe I'm wrong, since I learned how to do arithmetic with hexidecimal numbers before I learned what the heck a pointer was.. ??

5. Originally Posted by argv
Still, I maintain that, from my understanding at least, it all boils down to the fact that a "pointer" is simply an address. Like if you wanna find someones house.. you use their address.. if you want to store a value created by another function, you use it's address. That just seems, to me, a better approach to the understanding of pointers.. but, maybe I'm wrong, since I learned how to do arithmetic with hexidecimal numbers before I learned what the heck a pointer was.. ??
I still have no idea why you think hexadecimal has anything to do with pointers.

6. ## well....

Originally Posted by brewbuck
Reference is the concept, pointer is the implementation. The fact that a pointer is an address enables a lot of syntax you wouldn't have otherwise -- subtraction of pointers, incrementing and decrementing, testing for NULL, etc.

References I think are more confusing, because often they automagically dereference themselves, which is hard to explain. And they need not be implemented in terms of addresses, so it's difficult to talk about what a reference is actually "made of" other than saying it's just some sort of magic object that stands for some other object.

People have trouble with abstraction. Some people can't even grasp why functions are important. I'm not surprised that a lot of people can't figure out pointers, but what bothers me is the claim that pointers are intrinsically difficult to understand.

They aren't. What's hard to understand is why on Earth you'd need one.
There are alot of things that are used just to make code more organized and readable. Like using #define for anything besides a macro. I like the idea of pointers, because I like the idea that I can create something in one spot, and then if I want another function to be able to change that value based on some sort of (whatever), then it can. Thats the magic I guess.

It's not a huge deal to me, I'm not going to stand on the sidewalk preaching about how much I don't care for the term "pointer", I'm really just fueling conversation and debate I suppose. If I had to name it something, I would just call it an address. albeit, an address you can do math with, have a null value for, and whatever since it's not a text string, but an actual value.

7. ## ..

Originally Posted by brewbuck
I still have no idea why you think hexadecimal has anything to do with pointers.
The hexidecimal thing really is just because thats what it is on *my* system, and thats what it shows up as when I'm in debug. It's ALL binary. I'm not saying that it's always a hexidecimal or octal, or binary anything. But it's an address, otherwise known as a combination of bits that represent a real value of some sort.

8. Originally Posted by argv
Still, I maintain that, from my understanding at least, it all boils down to the fact that a "pointer" is simply an address. Like if you wanna find someones house.. you use their address.. if you want to store a value created by another function, you use it's address. That just seems, to me, a better approach to the understanding of pointers.. but, maybe I'm wrong, since I learned how to do arithmetic with hexidecimal numbers before I learned what the heck a pointer was.. ??
There is a slight complication. A pointer contains an address (or, that is what it's value should be) but a pointer also has an address of it's own, where it's value is stored. The later is generally irrelevant, but this distinguishes the concept of "memory address" from "pointer".

Pointer arithmetic generally does not involve hex. Eg, to move thru a string:
Code:
```#include <stdio.h>

int main() {
char string[]="hello world", *ptr=string;
int i;
while (ptr[0] != '\0') {
printf("%c",ptr[0]);
ptr++;
}
return 0;
}```
Hex is just a form of notation. ++ is 1, which is 1 in dec and hex. If you wanted to skip to the end of string, you could use +=0xb, but most people would use +=11. Hex is used alot with mem address because the numbers are big and (possibly) because most programmers will recognize a hex number as a memory address (but that is not the only place it is used).

9. ## why you would need one

Originally Posted by brewbuck
I've tried using an explanation similar to yours. It doesn't help much. The question is not what a pointer IS (most people can understand that part) but why you would need one.

And there's nothing special about hexadecimal. An address is an address, whether you express it in binary, decimal, hex, or encode it into a sonata using no instances of the musical note 'E'
You could probably write many programs without using a single pointer. From what i've been told or read, pointers are more about increasing performance than about being something necessary. "Don't pass a copy of the whole structure, just pass the address" is, I suppose, the idea there.

Of course, a programs gotta be pretty big before you have to worry about that much.

10. Originally Posted by brewbuck
References I think are more confusing, because often they automagically dereference themselves, which is hard to explain. And they need not be implemented in terms of addresses, so it's difficult to talk about what a reference is actually "made of" other than saying it's just some sort of magic object that stands for some other object.
As someone who learned perl and C nearly concurrently, I would say the two slightly different concepts shed a lot of light on each other -- probably because the reference is not implemented as an address. The concept of "reference" is pure pragmatism. I remember feeling that very clearly. Of course, I am now ashamed to admit it took me longer than 5 minutes to completely grasp either

Programming is magic, IMO. You could say a function "is a magical thing", a memory address "is a magical thing", etc, etc. Even with a knowledge of transistors and logic gates, I doubt anyone really conceptualizes all the way down to "reality" very often when writing code.

11. I know that I have no idea how an instruction decoder works. So I can't get down to transistors. But I think the really useful knowledge ends at the micro architecture level.

12. Originally Posted by argv
You could probably write many programs without using a single pointer.
As long as they are just about ints. Remember:
Code:
```char string[]="hello world";
printf("%p",string);```
Technically, "string" is a pointer. However, there are slightly more restrictions on it vis. applying pointer arithmetic (not allowed!).

13. ## true

Originally Posted by MK27
The last phrase is correct, but the "or is" is sort of non-sensical, like "is the sky really blue, or is it just the color of oxygen in the atmosphere?". The sky is blue, the color of oxygen in the atmosphere. A pointer is an address sent to a function that points to where a value is stored.

Going back to the street metaphor, and the Original Post, a map would be something of an area. If I wrote "123 Elm St." down on a piece of paper and gave it to you, you would not call it a map. And in fact map is a term in programming you will discover later, and it involves regions of memory.

Some (non-compiled) languages use something called a reference which is functionally identical to a pointer. The only word I have heard that might be more descriptive than "pointer" is "reference". On the other hand, pointer is a more unique word than "reference" -- it is not so overloaded semantically. So once you get the concept, pointer is probably more convenient, immediately recognizable, and less likely to be confused with something else. Maybe "referer" would be good if you do not have to say it five times fast

I agree 100% on that. But it is not because of the name; it is because of the strong elliptical tradition in programming "instructional" discourse, which is virtually the de facto standard. You could call it anything, it will not improve the quality of the material to which you refer.

Bravo brewbuck. That's the rub.

14. ## probably not..

Originally Posted by MK27
As someone who learned perl and C nearly concurrently, I would say the two slightly different concepts shed a lot of light on each other -- probably because the reference is not implemented as an address. The concept of "reference" is pure pragmatism. I remember feeling that very clearly. Of course, I am now ashamed to admit it took me longer than 5 minutes to completely grasp either

Programming is magic, IMO. You could say a function "is a magical thing", a memory address "is a magical thing", etc, etc. Even with a knowledge of transistors and logic gates, I doubt anyone really conceptualizes all the way down to "reality" very often when writing code.
No, probably not, but it might help. When determining how to write a program, I usually just as myself "how can I write it in a way that asks as few questions as possible." From the computers standpoint, well, it doesn't care. It'll do whatever, in order. The very concept of the computer or how computers came to be isn't magic. We needed a math machine because humans are not precise enough and prone to many mistakes. Back in the day, a human was called a "computer" if they computed stuff all day.

I'm just thankful we got past the Babbage math machine. As much fun as that looked to be.

15. Technically, "string" is a pointer.
No, it isn't. string is an array. Which is not the same thing as a pointer.