|  | pointer question |  | |
| | | mdh |  |
| Posted: Sun Jun 29, 2008 12:03 am Post subject: pointer question |  |
In one of K&R's exercises, I was caught out by my doing this.
If p is a pointer of type double, then
*--p was what I wanted, not --*p.
I know that the former returns a double one position before what p is currently pointing to, but what does --*p do? ( I think it is multiplying something, but not sure.)
Thanks |
| |
| | | pete |  |
| Posted: Sun Jun 29, 2008 12:03 am Post subject: Re: pointer question |  |
mdh wrote:
| Quote: | In one of K&R's exercises, I was caught out by my doing this.
If p is a pointer of type double, then
*--p was what I wanted, not --*p.
I know that the former returns a double one position before what p is currently pointing to, but what does --*p do? ( I think it is multiplying something, but not sure.)
|
--*p decrements the double that p points to.
Multiplication isn't defined for pointer operands.
-- pete |
| |
| | | mdh |  |
| Posted: Sun Jun 29, 2008 12:20 am Post subject: Re: pointer question |  |
On Jun 28, 5:17 pm, pete <pfil...@mindspring.com> wrote:
| Quote: | mdh wrote: In one of K&R's exercises, I was caught out by my doing this.
If p is a pointer of type double, then
*--p was what I wanted, not --*p.
I know that the former returns a double one position before what p is currently pointing to, but what does --*p do? ( I think it is multiplying something, but not sure.)
--*p decrements the double that p points to.
Multiplication isn't defined for pointer operands.
-- pete
|
I should have known that!! Thank you. |
| |
|
|