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

twig - Using Twigbridge in a Laravel 5.1 Package -

Kivy: Swiping (Carousel & ScreenManager) -

jdbc - Not able to establish database connection in eclipse -