Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Dans o/p

 
sun par
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Answer is b. Can someone explain why?
Thanks
 
Corey McGlone
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When this line executes:
i = i++ + m(i);
the operands are evaluated from left to right. First, the left hand operand is evaluated:
i = 0, so the equation becomes
i = 0 + m(i);
However, as we're using a post-increment operator, we now increment i to 1. Now we evaluate the next operand, m(i), by sending 1 to that method.
That results in the number 1 being printed, followed by a comma. Also, that method returns a 0, so our original formula evaluates to:
i = 0 + 0;
Therefore, the answer is: 1,0
I hope that helps,
Corey
 
sun par
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Corey
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic