help with increment and decrement

hi everybody ...
can anybody tell me what is wrong with these statment

cout << ++x++;
cout << x++ + 1;<< i run it in the compiler and give me 2 ? why .. i dont hve no idea ??!!
cout << x++ + ++1;
cout << ++( x + y );

or give a hint or anything that will help and make me understand the increment and decrement "thing" because i dont get it ...
i run it in the compiler and give me 2

You didn't initialise x, so the result could be anything at all.
i initialized as x = 1 and gave me 2 ..could you explain why ...
1
2
3
4
5
6
7
   int x;

   x = 1;
   cout << "A " << x++ + 1 << endl;

   x = 1;
   cout << "B " << ++x + 1 << endl;
A 2
B 3


That's the basic nature of pre-increment and postincrement.
Line A retrieves the value of x at the start. Then x is incremented afterwards.
Line B first increments x, then retrieves the value.
Topic archived. No new replies allowed.