java - What does the ++counter mean? -


this question has answer here:

i don't consider myself bad @ programming, there's been troubling me since past few days.

int counter = 3; ++counter; 

is following code above same counter++;.

it similar, not same.

in expression doesn't matter, if had more complicated, system.out.println(counter++), make big difference.

for example: int counter = 3; system.out.println(counter++)

this print 3, increment counter 4.

however, if do

int counter = 3; system.out.println(++counter)

it print 4 because increments prior giving value parameter print function.

it's question of when increment performed, prefix performs before other operations, postfix performs after. have different precedences.


Comments

Popular posts from this blog

java - BeanIO write annotated class to fixedlength -

Using Java 8 lambdas/transformations to combine and flatten two Maps -

How to connect android app to App engine -