By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,419 Members | 1,124 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,419 IT Pros & Developers. It's quick & easy.

Pointer issues

P: n/a
bob
In some code I have the following:

1) (*p) ->value;
2) *p->value;

1) gives an error while 2) works. What are the difference between 1)
and 2)?

Jun 9 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On 2007-06-09 16:41, bob wrote:
In some code I have the following:

1) (*p) ->value;
2) *p->value;

1) gives an error while 2) works. What are the difference between 1)
and 2)?
1 will first try to dereference p and then call the -on what p points
to, this will only work if what p points to have overloaded that
operator or if p is of type T** (pointer to pointer).

2 on the other hand first uses the -operator on p and then
dereferences value (meaning that value is a pointer). So another way to
write 2 is *(p-value).

--
Erik Wikström
Jun 9 '07 #2

P: n/a
"bob" <tu*****@gmail.comwrote in message
news:11**********************@w5g2000hsg.googlegro ups.com...
In some code I have the following:

1) (*p) ->value;
2) *p->value;

1) gives an error while 2) works. What are the difference between 1)
and 2)?
You need to look up "operator precidence". That states what order the
compiler will interpret operators. -has a higher precidence than *
(dereference). So -is evaluated first giving you:
*(p->value).
Jun 10 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.