r/programming • • Jul 23 '08

Ask Programming: What language did you first start, and how old were you?

12 Upvotes

188 comments sorted by

View all comments

Show parent comment

6

u/[deleted] Jul 23 '08 edited Jul 24 '08

pointers do not in general have addresses.

Yeah. Pointers don't require storage! They're Magic!

A pointer has an address:

int main(void) {
    char *s = "foo";

    printf("%p\n", s);
    printf("%p\n", &s);

    return(0);
}

Prints:

0x8048480
0xbfc911c0

The first of which is the address in memory where the string "foo" resides. The second is the address in memory where the pointer resides.

edit: I understand we're just talking terminology here. The problem is, if you're not going to call it a 'pointer', then what are you gonna call it? In my interpretation, a pointer is the type. The pointer occupies memory (32 bits on a 32-bit architecture, AFAIK0, has an address, and contains an address. The pointer points to the address it contains, which is the address of something else in memory, whatever it is.

0

u/wildeye Jul 24 '08

It's not just terminology. Similarly to what I said nearby, "&a" is an address, but it doesn't have an address, now does it?

"&a" is a value, and although in some contexts it gets stuck in memory, it most certainly does not always get stuck in memory.

So since "&a" is a pointer, it follows that pointers do not always occupy memory.

You and others are thinking of the instances where there is a variable of type pointer-to-something. But pointers exist even in the absence of such variables, you see.