Working of pre-fix increment in Java -


what control flow of post-increment operator?

public class postincrement {     public static void main(string[] args)     {          int = 0;         for(int i=0;i< 2 ;i++)         {             =a++;              }          for(int i=0 ;i< 1;i++)         {             a++;         }          system.out.println("result2 :"+" "+a);             }  } 

the results 0 , 1

why so?

the postfix operator ++ executes after statement completes.

the first time print value of a prints 0 because nothing has changed. next, enter loop executes once, incrementing value of a. doesn't matter postincrement because there no other instructions in statement. value of a 1.

you print out 1.

as aside, code doesn't work because inner variable i hiding outer variable , compiler error redeclaring i. assumed mean different variable here such j.


Comments

Popular posts from this blog

user interface - Python attempting to create a simple gui, getting "AttributeError: 'MainMenu' object has no attribute 'intro_screen'" -

jquery - Common JavaScript snippet to share files on Google Drive, Dropbox, Box.net or SkyDrive -

Android Gson.fromJson error -