C ++ and Java on expressions of expressions

zhaozj2021-02-17  92

/ * In the process of learning Java, I found that the original C 's interpretation order and Java have a large different C is from left to right. Java is a scanning of high priority. Here is a test I did. * / public class testgreeting {public static void main (String [] args) {add1 (); add11 (); add2 (); add22 ();} public static void add1 ()} public static void add1 ()} public static void add1 (); ( ) i) ( i) ( i) "); // 4 int i = 3, J; j = i; system.out.println (" i = " i); // 4 system.out.println ("j =" j); // 4

i = 3; j = ( i) ( i); system.out.println ("i =" i); // 5 system.out.println ("j =" j); / / 9 4 5

i = 3; j = ( i) ( i) ( i); system.out.println ("i =" i); //6 system.out.println ("j = " J); // 15 4 5 6 / * Borland C Builder Example INT I = 3, J;

J = (i ); showMessage ("i =" INTSTR (i)); // 4 showMessage ("j =" INTOSTR (j)); // 3 3

i = 3; j = (i ) (i ); showMessage ("i =" INTOSTR (i)); // 5 showMessage ("j =" INTOSTR (J)); // 6 3 3

i = 3; j = (i ) (i ) (i ); showMessage ("i =" INTOSTR (i)); // 6 showMessage ("j =" INTOSTR (J)); // 9 3 3 3 * /} public static void add11 () {system.out.println (" i i"); // 4 I = 3, J; J = I; System.out.Println ("i =" i); // 4 system.out.println ("j =" j); // 4

i = 3; j = i i; system.out.println ("i =" i); // 5 system.out.println ("j =" j); // 9 4 5i = 3; j = i i i; system.out.println ("i =" i); //6 system.out.println ("j =" j); / / 15 4 5 6} public static void add2 () {system.out.println ("(i ) (i ) (i )"); // 4 int i = 3, j; j = (i ); System.out.println ("i =" i); // 7 system.out.println ("j =" j); //6

i = 3; j = (i ) (i ); system.out.println ("i =" i); // 5 system.out.println ("j =" j); // 7 3 4

i = 3; j = (i ) (i ) (i ); system.out.println ("i =" i); //6 system.out.println ("j =" j); / / 12 3 4 5 / * Borland C Builder Example INT i = 3, J;

J = (i ); showMessage ("i =" INTSTR (i)); // 4 showMessage ("j =" INTOSTR (j)); // 3 3

i = 3; j = (i ) (i ); showMessage ("i =" INTOSTR (i)); // 5 showMessage ("j =" INTOSTR (J)); // 6 3 3

i = 3; j = (i ) (i ) (i ); showMessage ("i =" INTOSTR (i)); // 6 showMessage ("j =" INTOSTR (J)); // 9 3 3 3 * /} public static void add22 () {system.out.println ("i "); // 4 int i = 3, j; j = i ; system.out.println "i =" i); // 7 system.out.println ("j =" j); // 6

i = 3; J = i i ; system.out.println ("i =" i); // 5 system.out.println ("j =" j); // 7 3 4i = 3; J = i i i ; system.out.println ("i =" i); //6 system.out.println ("j =" j); // 12 3 4 5}}

转载请注明原文地址:https://www.9cbs.com/read-31400.html

New Post(0)