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

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -