• Post Reply Bookmark Topic Watch Topic
  • New Topic

please give the execution flow for the code  RSS feed

 
yogesh srinivasan
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
class Test
{
public static void main(String args[])
{
int a=9;
a=a+++a;
System.out.println(a);
}

}

I'm getting ans as

19
 
fred rosenberger
lowercase baba
Bartender
Posts: 12563
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i'm not positive, but i think it's this...

a+++a resolved to

a + (++a)

so, you get 9 + 10
 
Sasha Ruehmkorf
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nope, it's
a++ + a = 9 + 10 = 19. See the following:

The compiler parses the given expression from left to right
[ June 09, 2007: Message edited by: Sasha Ruehmkorf ]
 
yogesh srinivasan
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks guys
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!