| Author |
Operators & Assignments
|
Abi Raj
Greenhorn
Joined: Jan 28, 2005
Posts: 28
|
|
I have some doubts in Operators & Assignments. pls clarify them 1) Is (--1) a valid expression? If not why. 2) Is (+-+-+-1) a valid expression?? 3) what will be the output of the following program public class Evaluationorder{ public static void main(String[] args) { int[] array = {4,8,16}; int i = 1; array[++i] = --i; System.out.println(array[0]+array[1]+array[2]); } } when I run the program it prints 13. Can somebody explain it??
|
 |
Jay Pawar
Ranch Hand
Joined: Aug 27, 2004
Posts: 411
|
|
At Line X First i gets incremented to 2, we have array[2] = --i; and then i gets decremented by 1 so i = 1. So finally array[2] = 1; So when you add array[0] = 4 , array[1] = 8 and array[2] = 1 you get output as 13. Hope that helps you...
|
Cheers,<br />Jay<br /> <br />(SCJP 1.4)<br />Heights of great men were not achieved in one day, they were toiling day and night while their companions slept.
|
 |
 |
|
|
subject: Operators & Assignments
|
|
|