• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

about ++.

 
Ranch Hand
Posts: 317
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, all, when we write

It will be:

or:

Thanks in advance.
Guoqiao
 
Ranch Hand
Posts: 2378
MySQL Database Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It will be interpreted as i++ +i
------------------
azaman
 
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

since the output is 3 it is evident that the compiler would interpret the line as follows
i + (++i)
hope that helps
Samith.P.Nambiar
 
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Even i++(+i) is 3. -
I think it resolves from Left to Right so it is i++(+i).
Thanx
Rajani
 
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
code:
--------------------------------------------------------------------------------
class Test{public static void main(String[] arg){int i = 1;int j = i+++i;System.out.println(j); //prints 3}}
--------------------------------------------------------------------------------
since the output is 3 it is evident that the compiler would interpret the line as follows
i + (++i)
hope that helps
Samith.P.Nambiar
----------------------
Hai Nambiar,
Need not be & it is not the case.
j=i+++i = i++ +i;
j=1++ +i; // i assigned 1 and post incremented to 2.
j=1+2; // postincremented value of i is substituted.
j= 3 // The value, 3 is arrived at.

HTH

tvs sundaram

[This message has been edited by tvs sundaram (edited August 13, 2001).]
 
Samith Nambiar
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi rajani
the issue of resolving from Left to Right would only come into picture in the case of associativity ... but i think there is no question about it here.
I think i + (++i) would be true because pre-increment operator the highest priority
Samith.P.Nambiar
 
Samith Nambiar
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Need not be & it is not the case.
j=i+++i = i++ +i;
j=1++ +i; // i assigned 1 and post incremented to 2.
j=1+2; // postincremented value of i is substituted.
j= 3 // The value, 3 is arrived at.


as far as i understand
1. Precedence - the unary prefix and postfix have the highest precedence.
2. Associativity - Right to Left


so keeping these points in mind i would interpret j=i+++i as
j = i + (++i) // which is 3


this is the reason for my earlier answer to this post ... if u disagree pls get back to this topic
thanx
Samith.P.Nambiar
 
Ashik Uzzaman
Ranch Hand
Posts: 2378
MySQL Database Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ranchers,
Follow the code below

------------------
azaman
 
Ranch Hand
Posts: 356
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I agree with you Ashik,U r rite the flow is like
i+++j = (i++) +j
Thanks for clearing this.
--Farooq
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic