Velocity Reviews > newbie question: difference between (*ptr) and *ptr

# newbie question: difference between (*ptr) and *ptr

hans christian
Guest
Posts: n/a

 06-10-2006
Hello everyone,

Could someone explain to me what the difference is between
(*ptr)

and

*ptr

I am a bit confused, since I am just starting to program in C.

Thank you for any clear answers !

HHcrist.

Ben Pfaff
Guest
Posts: n/a

 06-10-2006
hans christian <(E-Mail Removed)> writes:

> Could someone explain to me what the difference is between
> (*ptr)
>
> and
>
> *ptr

There is no difference in isolation. Perhaps you should explain
--
int main(void){char p[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuv wxyz.\
\n",*q="kl BIcNBFr.NKEzjwCIxNJC";int i=sizeof p/2;char *strchr();int putchar(\
);while(*q){i+=strchr(p,*q++)-p;if(i>=(int)sizeof p)i-=sizeof p-1;putchar(p[i]\
);}return 0;}

hans christian
Guest
Posts: n/a

 06-10-2006
On Sat, 10 Jun 2006 16:29:47 -0700, Ben Pfaff wrote:

> hans christian <(E-Mail Removed)> writes:
>
>> Could someone explain to me what the difference is between
>> (*ptr)
>>
>> and
>>
>> *ptr

>
> There is no difference in isolation. Perhaps you should explain

My situation is that I am reading Numerical recipes in C, and in the misc.
functions they mix the previous given notation. That confuses me, because
I do not know what the difference might be, or can discover any coherent
usage of the two different notations.

For example some arbitrary snippets from the same function:

*adev = (*var) = (*skew) = (*curt) = 0.0;
*var += (p = s * s);
*skew /= (n * (*var) * (*sdev));

In the first (*skew) is used, but in the last line they use the other form
*skew ?

THank you for the quick reply.

HHcrist

Ben Pfaff
Guest
Posts: n/a

 06-11-2006
hans christian <(E-Mail Removed)> writes:

>> hans christian <(E-Mail Removed)> writes:
>>
>>> Could someone explain to me what the difference is between
>>> (*ptr)
>>>
>>> and
>>>
>>> *ptr

[...]

> *adev = (*var) = (*skew) = (*curt) = 0.0;

No difference between the two forms here.

> *var += (p = s * s);

Here the parentheses serve the valuable purpose of making it
clear what's going on. It would be even better written as
p = s * s;
*var += p;

> *skew /= (n * (*var) * (*sdev));

No purpose, except a subjective difference in readability.
--
"You call this a *C* question? What the hell are you smoking?" --Kaz

xhoster@gmail.com
Guest
Posts: n/a

 06-11-2006
hans christian <(E-Mail Removed)> wrote:
> On Sat, 10 Jun 2006 16:29:47 -0700, Ben Pfaff wrote:
>
> > hans christian <(E-Mail Removed)> writes:
> >
> >> Could someone explain to me what the difference is between
> >> (*ptr)
> >>
> >> and
> >>
> >> *ptr

> >
> > There is no difference in isolation. Perhaps you should explain

>
> My situation is that I am reading Numerical recipes in C, and in the
> misc. functions they mix the previous given notation. That confuses me,
> because I do not know what the difference might be, or can discover any
> coherent usage of the two different notations.
>
> For example some arbitrary snippets from the same function:
>
> *adev = (*var) = (*skew) = (*curt) = 0.0;

Although C doesn't care, I like the paranthesis for readability.
It would take me a few seconds to realize they are not multiplications.

> *var += (p = s * s);
> *skew /= (n * (*var) * (*sdev));
>
> In the first (*skew) is used, but in the last line they use the other
> form *skew ?

In the least line, it takes little mental effort to realize it is not
a multiplication.

Xho

--
Usenet Newsgroup Service \$9.95/Month 30GB

hans christian
Guest
Posts: n/a

 06-11-2006
On Sun, 11 Jun 2006 00:42:51 +0000, xhoster wrote:

> hans christian <(E-Mail Removed)> wrote:
>> On Sat, 10 Jun 2006 16:29:47 -0700, Ben Pfaff wrote:
>>
>> > hans christian <(E-Mail Removed)> writes:
>> >
>> >> Could someone explain to me what the difference is between
>> >> (*ptr)
>> >>
>> >> and
>> >>
>> >> *ptr
>> >
>> > There is no difference in isolation. Perhaps you should explain

>>
>> My situation is that I am reading Numerical recipes in C, and in the
>> misc. functions they mix the previous given notation. That confuses me,
>> because I do not know what the difference might be, or can discover any
>> coherent usage of the two different notations.
>>
>> For example some arbitrary snippets from the same function:
>>
>> *adev = (*var) = (*skew) = (*curt) = 0.0;

>
> Although C doesn't care, I like the paranthesis for readability.
> It would take me a few seconds to realize they are not multiplications.
>
>> *var += (p = s * s);
>> *skew /= (n * (*var) * (*sdev));
>>
>> In the first (*skew) is used, but in the last line they use the other
>> form *skew ?

>
> In the least line, it takes little mental effort to realize it is not
> a multiplication.
>
> Xho

Ok super... ! Thank you for the answers. I'm a bit more secure in my
understanding now.. thankx..

HHcrist