4 ms·
I was taught in CS101, as I think just about everyone is, that the & operator means "the address of." So parsing &x + 1 into English becomes: "The address of
by drblast 16y ago
I was taught in CS101, as I think just about everyone is, that the & operator means "the address of."
So parsing &x + 1 into English becomes:
"The address of x plus one."
Except that, more explicitly, we should say:
"The address of x plus one times the size of the type of x."
What you should say is so far removed from the C code appears to say (add 1 to something) that confusion is inevitable.
That the second term should depend on the implicit type information from the first term, especially when the "address" operator has precedence over the + operator, seems backward to me.
To me an address is just a number, it carries no type information. Translate to s-expressions:
(+ (address-of x) 1)
Does it make sense that the 1 would change value based on the result of "address-of"? Not to me. I think it's bad design. Now, if it were taught differently:
(+ (typed-reference-to x) 1)
Then it makes more sense.