Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

a[i]=i=9

 
lucy hu
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, all, this one is from the JavaQuest Mock Exam,
What happens during execution of the following program?
1. public class OperandOrder {
2. public static void main(String args[]) {
3. int i=0;
4. int a[] = {3,6};
5. a[i] = i = 9;
6. System.out.println(i + " " + a[0] + " " + a[1]);
7. }
8. }
I'm confused about the answer: 9, 9, 6
could anybody explain how "a[i] = i = 9" is excuted?
Lucy
 
Cherry Mathew
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it will be 9,6,6
just check once more
itz bcos when we assign first
a[0] = i = 9; is done
then a[0] = 9;
is done
 
sunilkumar ssuparasmul
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the order od evaluation is left 2 right whereas for assignment the order of execution is right 2 left .
Hope this is clear
------------------
"Winners don't do different things
They do things differently"
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic