Vijay said:
Hi,
Why multiplication of pointers is not allowed?
Till now I only know this, but not the reason why!
PS: As a rule, I searched the FAQ, but could not
find an answer.
The result would be meaningless. An easy (but
informal) way to understand this is to use an analogy:
think of pointer values as street addresses. Then
the following operations make sense:
- Find the house at "123 Main Street."
- To find the neigboring house, compute "123
Main Street plus one." (I'm ignoring such
real-world intrusions as odd-even numbering
schemes, discontinuities between city blocks,
and so on: we're just exploring an imperfect
analogy, after all.)
- To find the distance between two Main Street
addresses, compute "123 Main Street minus 189
Main Street," yielding "minus 66 lots."
However, some other arithmetical operations make
no sense at all:
- Computing "123 Main Street plus 207 Main Street"
produces no useful answer.
- Computing "123 Main Street minus 123 Elm Street"
produces no useful answer.
- Similarly, computing "123 Main Street times
89 El Camino Real" makes no sense. Perhaps the
result might be considered a kind of "area,"
but there seems to be no useful analogous
concept to "area" in the addressing of memory-
resident objects.
- Finally, computing "123 Main Street times three"
might possibly make sense, arriving at "369 Main
Street." But such a definition carries a built-
in assumption that Main Street is zero-based,
and in a linear computer memory no more than one
object can begin at "address zero." If you want
to find the house three times as far from the
start of the street, you really want to compute
"Main Street Origin plus three times (123 Main
Street minus Main Street Origin)."