Consider The Following Statements

These Two Are Equals.can Someone Explain Me How.
Is Parentehsis Not Alter The Behaviour? :?:

Recommended Answers

All 3 Replies

Postfix ++ has a higher precedence than prefix *. Compiler help has a table of precedence, you can look them up.

So that means that the ++ 'binds' to p before the * is considered. Your parens don't change that. Consider this, though:


That means increment the contents of what p points to. Here the parens are needed because you are overriding the default binding.

Now try:

This is the same as (*p)++, but you don't need parens. Why? [] have the same precedence as postfix ++, but the SECOND rule is that you evaluate these left-to-right. Most bindings evaluate left-to-right, except for unary operators (prefix ++, --, etc) and typecasts. Again, this will be in the compiler help file or a book under 'operator precedence'.

Postfix ++ has a higher precedence than prefix *.

I think that this explanation is a little more detailed.

Yup, there are many more detailed explanations on the web of how programming works than I could ever hope to explain.

In the future I'll wait a while for others to answer these questions before attempting an answer myself. Since everything about basic C/C++ usage exists on the web in forums, docs, and sample code it sort of makes it pointless to try to answer a question without a link :-(

(no wonder my reputation sucks)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.