Be familiar with i++ and ++i in C/s + +, then do you know what the following Java code effect is?
One, code example
/** * * @authorElelule **/ Public classTestplusplusoperator { Public voidtest1 () {inti = 0; I= i++; System.out.println (i); } Public voidtest2 () {inti = 0; I= ++i; System.out.println (i); }}
Second, the output results
01
Three, byte code
Public voidtest1 (); Code:0: Iconst_01: Istore_12: iload_1//Put the I load of unit 1th in the storage stack frame on the operand stack frame 3:iinc 1, 1/ /Add 1 6 to the data in unit 1th in the stack frame: istore_1//Save the data on the action stack frame to unit 1th of the storage stack frame 7:getstatic #2//Field Java/lang/system.out:ljava/io/printstream;10: Iload_111:invokevirtual #3//Method java/io/printstream.println: (I) V14:return Public voidtest2 (); Code:0: Iconst_01: Istore_12:iinc 1, 1//Add 1 5 to the data in unit 1th in the storage stack frame: iload_1//Will store 1 in the stack frame Number of data in cell load to operand stack frame 6: istore_1//Save data in the stack frame to unit 1th in the storage stack frame 7:getstatic #2//Field Java/lang/system.out:ljava/io/printstream;10: Iload_111:invokevirtual #3//Method java/io/printstream.println: (I) V14:return
Iv. Summary
From the above byte code can be seen,i=i++; This statement was translated into "first move, then the data in the storage unit plus 1, and finally the original data to be moved back", and i=++i; This statement is translated to "Add 1 to the data in the storage unit, then move away, and then move back". is it not the same in C + +? Of course! Can you try these two statements output in C language, or rather?
i++ and ++i in Java