A
aruna
Why division/mulitiplication/addition of pointers are not
allowed in C?
allowed in C?
aruna said:Why division/mulitiplication/addition of pointers are not
allowed in C?
aruna said:Why division/mulitiplication/addition of pointers are not
allowed in C?
Lew said:-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
aruna wrote:
| Why division/mulitiplication/addition of pointers are not
| allowed in C?
A pointer can be considered to be the 'location' of a data item.
Subtraction of one pointer from another gives you the 'distance' between
two data items.
What would addition of two pointers give you? (Hint: What does the
addition of '12 Oak Lane' to '757 Main Street West' give you?)
What would multiplication of two pointers give you? (Hint: What does the
multiplication of '12 Oak Lane' with '757 Main Street West' give you?)
What would division of two pointers give you? (Hint: What does the
division of '12 Oak Lane' by '757 Main Street West' give you?)
While pointer subtraction is meaningful, the other operations are not.
- --
Lew Pitcher, IT Consultant, Enterprise Application Architecture
Enterprise Technology Solutions, TD Bank Financial Group
aruna said:Why division/mulitiplication/addition of pointers are not
allowed in C?
CBFalconer said:Using right forefinger, point to nose. Using left forefinger,
point to right ear. Now define the product, sum, ratios of those
pointers.
In said:Why division/mulitiplication/addition of pointers are not
allowed in C?
One can add a scalar quantity to a pointer to a new location.
For example, "Move 3 houses north of 12 Oak Lane", makes sense.
If two pointers can be subracted for a distance then a distance
should be added from one pointer to generate a new pointer value.
This analogy is lost on me. If I subtract one of those pointers from the
other, then what body part would I be pointing to now?
None. But you have the distance between your nose and your right ear. C
works like that too. Now define the product, sum and ratio of those
pointers. Either in real-world or C terms.
Why division/mulitiplication/addition of pointers are not
allowed in C?
aruna said:Why division/mulitiplication/addition of pointers are not
allowed in C?
Rakesh Kumar said:Addition / subtraction is definitely allowed, the reason being pointers
refer to address and you can back and forth in the memory space. (Say,
as in an array as the memory is allocated continuously ).
Why division/mulitiplication/addition of pointers are not
allowed in C?
Rakesh Kumar said:Addition / subtraction is definitely allowed, the reason being pointers
refer to address and you can back and forth in the memory space. (Say,
as in an array as the memory is allocated continuously ).
Where did anyone mention a scalar quantity?
Addition of two pointers is not allowed, addition of a pointer and a
scalar is.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.