Question: > 
> **Possible Duplicate:**  
> 
> [Order of evaluation of arguments using std::cout](https://stackoverflow.com/questions/7718508/order-of-evaluation-of-arguments-using-stdcout) 
> 
> 
> 

**I have known it now!This is responsible for *'cout'***
The all code:

```
#include <iostream>
using namespace std;
int main()
{
   int i = 3;
   cout <<-i++<<endl<<i<<endl<<-(i++)<<endl<<i<<endl;
   return 0;
}

```

I use VC++6.0 to compile,output is : `-4 4 -3 3`
But I use g++ to compile,output is : `-4 5 -3 5`
Why? I think they should be the same : `-4 4 -4 4`

PS:I try it： 

```
int main()
{
   int i = 3;
   cout <<-i++<<endl;
   return 0;
}

```

And

```
int main()
{
   int i = 3;
   cout <<-（i++）<<endl;
   return 0;
}

```

I compile they one by one,the result is the same:-3 3
Thinks to all answers,I maybe have a mistake of testing -i++ and -(i++) somehow

Answer: 
As it stands right now, your code has undefined behavior. You're both using the value of `i` and modifying `i` without an intervening sequence point1. This gives undefined behavior.

The difference in results between the two lines does *not* stem from the use of parentheses -- it stems purely from the fact that the `++` in the first line modifies the value of `i`, so when you reach the second line, its value has been incremented.

To summarize, since you have undefined behavior, *any* output is perfectly reasonable and allowed, but the `-4 4 -3 3` is quite reasonable and understandable.

---

1. As of C++ 11, the standard no longer uses the phrase "sequence point", but uses phrasing like "sequenced before" or "sequenced after" to describe the same basic intent. A *few* things ended up getting defined behavior from this change, but not many (and, specifically, not this code).
The two lines are the same

Try 

```
int i = 3;
cout << - i++  << endl << i << endl;
i=3
cout << -(i++) << endl << i << endl;

```

The operator precedence for any operator is found here:

<http://en.cppreference.com/w/cpp/language/operator_precedence>

And, *postfix ++* (the one you use) has higher precedence than *Unary plus and minus*.

On the other hand, you should read this Q and A:

[Why is a = i + i++ undefined and not unspecified behaviour](https://stackoverflow.com/questions/12572618/why-is-a-i-i-undefined-and-not-unspecified-behaviour)

Your examples are actually identical to this:

```
(
  (
    (
      cout.operator<<(-(i++))
    ).operator<<(endl)
  ).operator<<(i)
).operator<<(endl);

```

In essence, modifying a variable and using it in the same expression is often *undefined behaviour*: the program is allowed to do *anything*.