Consider The Following Statements

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

14 Years
Discussion Span
Last Post by Chainsaw

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


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)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.