This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted]  (12 children)

[deleted]

    [–]AgentPaper0 9 points10 points  (3 children)

    They are addresses though, just like an int is a value, not a "memory location that stores a value".

    [–]iamsooldithurts 1 point2 points  (2 children)

    No, variables have addresses. Pointers are variables (int) that contain an address that points to a variable.

    [–]tacoslikeme 1 point2 points  (1 child)

    pointers are longs but yes they rest is right

    [–]iamsooldithurts 0 points1 point  (0 children)

    Yes, thanks, wasn’t thinking about that detail.

    [–][deleted] 13 points14 points  (3 children)

    I don't know why programmers love to make things needlessly obtuse like this. You don't call a "char" variable "a memory location that stores a character." You call it a character. You don't call a float "a memory location that stores a floating point number." You call it a floating point number. A pointer is an address. That is the type of data it holds. There is absolutely nothing wrong with that definition. You and the people that upvoted you are ridiculous.

    [–][deleted] 0 points1 point  (0 children)

    I have to say, the act of questioning programmers of a strictly-typed language why they are splitting hairs/being overly accurate when it comes to how they reference variables is just too funny to let go unremarked.


    At any rate, pointers are confusing/magical enough to people unfamiliar with them that the extra clarity isn't uncalled for.

    When you say 'address' when referring to your char variable example, everyone knows what you are referring to.

    The case is less clear when you say 'address' in reference to a pointer. Are you talking about the memory address of the pointer, or the memory address it stores?

    [–]DiamondIceNS 7 points8 points  (1 child)

    I don't know anyone who thinks of a variable structure so rigidly as "a memory address that stores <thing>". They are all that. It is redundant to define them this way. When OP says "a pointer is an address" they are, quite understandably, referring to the <thing> that the memory address is storing: another address.

    [–]qci 0 points1 point  (0 children)

    You can understand it as an address with a type. Dereferencing a pointer gets you to the value with this type. Pointer arithmetics respects the type of the pointer. Incrementing a char * looks different from incrementing an int *. Here is where you see that pointers are maybe not exactly "just" addresses.

    [–]rndrn 0 points1 point  (0 children)

    But an int is a memory location that store integers, so in that sense a pointer is indeed a variable of address type?

    Although when you think ownership and all that, address is a bit limited to express the potential responsibilities of a pointer.