hello i just wanna know that in the following java code which operator has the highest precedence int h = 5 , y ; y = ++h + h++ + (h++ + 5); system.out.println(y); there i use bracket and a postfix operator inside it. now my question is what will computer do first it deals with brackets or it deals with postfix operator. thank you ali asghar ------------------
I think first the compiler will go inside the bracket and solve the matter inside it means first add the values and then increase the value of h and then will solve the rest of th problem. Please correct me if i'm wrong, b-cos this just my opinion.
If I'm not mistaken, the output of this program would be 24. First the variables inside of the parentheses are evaluated first, (h++ + 5) which equals 10 and h now equals 6 (the value is used first, then the variable is incremented). Then the prefix operator is evaluated on h making h 7 now. Then it adds the 7 plus another 7 making 14. h is incremented after evaluating. And 14 + 10 equals 24. Here are the steps: h = 5; y = ++h + h++ + (h++ + 5); // y = ++h + h++ + (5 + 5); // h = 6 now y = ++h + h++ + 10; y = 7 + h++ + 10; // h = 7 now y = 7 + 7 + 10; // h = 8 now y = 24 Hope that's clear... ------------------ Michael J Bruesch Codito, ergo sum... I code, therefore I am. http://www.geocities.com/mjbruesch
Michael J Bruesch<br /><i>I code, therefore I am.</i>
ali_the_great_one Hi, and welcome to the ranch. The javaranch has thousands of visitors here all the time and has established a naming policy to help try to make this site a more professional forum for everyone. Your name is not in keeping with that policy, please read it and change your name to comply with this policy. Basically you should use your real first and last name with a space in the middle. Thanks for your cooperation and please dont be a stranger to the ranch.
------------------ Dave Sun Certified Programmer for the Java� 2 Platform