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

H

hans christian

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.
 
B

Ben Pfaff

hans christian said:
Could someone explain to me what the difference is between
(*ptr)

and

*ptr

There is no difference in isolation. Perhaps you should explain
your situation.
 
H

hans christian

There is no difference in isolation. Perhaps you should explain
your situation.

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
 
B

Ben Pfaff

hans christian said:
[...]

*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.
 
X

xhoster

hans christian said:
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
 
H

hans christian

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


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
 

Ask a Question

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.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top