# Really Quick n00b question, should take three seconds to answer

• February 12th, 2011, 11:02 PM
joeschmidt45
Really Quick n00b question, should take three seconds to answer
Code :

```int n = 5; n = n++; System.out.println(n);```

Well, this prints out 5, can anyone explain please? Thanks!
• February 12th, 2011, 11:21 PM
copeg
Re: Really Quick n00b question, should take three seconds to answer
See the response to Help with prefix/postfix
• February 13th, 2011, 12:35 AM
suxen
Re: Really Quick n00b question, should take three seconds to answer
edit - nevermind
• February 22nd, 2011, 06:59 AM
yasuocodez
Re: Really Quick n00b question, should take three seconds to answer
It is bad coding because n is initialized with 5, then n is incremented to 6 and then n is equal to 6.
When n is incremented to 6 it is the same thing as saying n = n + 1; n++ is called a short hand or idiom.
So what is happening is this...
Code :

```  int n = 5; n = (n = n + 1); System.out.println(n);```

!!
• February 24th, 2011, 04:23 AM
dlorde
Re: Really Quick n00b question, should take three seconds to answer
Quote:

Originally Posted by yasuocodez
It is bad coding because n is initialized with 5, then n is incremented to 6 and then n is equal to 6.
When n is incremented to 6 it is the same thing as saying n = n + 1; n++ is called a short hand or idiom.
So what is happening is this...
Code :

```int n = 5; n = (n = n + 1); System.out.println(n);```

!!

No; it is bad code, but that's not what is happening, you've missed the whole point - the OP wants to know why the output is 5 instead of 6.

The result of the postfix expression is the original value; the increment operation is performed on the right hand expression value after the assignment and is, in this case, thrown away.