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. -- Vijay Kumar R Zanvar My Home Page - http://www.oocities.org/vijoeyz/ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ On Tue, 6 Jan 2004 12:37:08 +0530, "Vijay Kumar R Zanvar" <vijoeyz@hotpop.com> wrote: >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. Adding an int to a pointer results in pointing to something a specified distance further to the "right" in memory. Subtracting an int from a pointer results in pointing to something a specified distance further to the "left" in memory. Subtracting one pointer from another results in how far apart the two memory locations are. If your program and data were to be magically relocated as a unit in memory, each of the above expressions would still produce the same result. Until you can define a concept of either adding two pointers or multiplying two pointers that meets the constraint in the previous paragraph, the two operations make no sense. (Hint: others have thought this through and decided such a definition is either not possible or of no programming value.) <<Remove the del for email>> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Vijay Kumar R Zanvar wrote: > > 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)." -- Eric.Sosman@sun.com ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~