• 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

Is assignment precedence(=) higher than postfix unary assignment(var++)

 
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


TABLE 2 . 1
Operators in Java, in Descending Order of Precedence
Category Operators
Unary
++ -- + - ! ~
(type)
Arithmetic
* / %
+ -
Shift
<< >> >>>
Comparison
< <= > >= instanceof
== !=
Bitwise
& ^ |
Short-circuit
&& ||
Conditional
?:
Assignment
=
op=



Mr Sandeep and Sybex both say that ++ operator has a higher precedence than = ,

But What i think is
1)++ has a higher precedence than = //True
i agree fully to this,no compromise.(Sybex Complete Java Certification says that)

2)prefix ++ has a higher precedence than = //True
no doubts on that too(a=++i) ; so no problem here.

3)postfix ++ has a higher precedence than = //True according to Mr Sandeep
//But False According To Me(i=j++) ;

here first i is assigned the value of j,and then j is incremented.

I know i might be wrong,but it goes like this,
Comments Requested To Clear The Doubts.

Thanks,
Anand
[ September 16, 2005: Message edited by: anand phulwani ]
 
Ranch Hand
Posts: 340
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You must probably be knowing Anand that assignment statements are evaluated from left to right.
if
i=0;

so here
k=i++;
1) i is evaluated first which results in 0
2) Value of i taken in buffer (we can consider so) ie. 0
3) then increment i by 1 resulting in value of i being 1;
4) Buffered value is assigned to k;

and all this according to precedence.

but here:
k=++i;

1) ++ is evaluated first which results in value of i being 1
2) Value of i taken in buffer (we can consider so) ie. 1
4) Buffered value is assigned to k ie. 1

hope it will help you..
Sandy
 
anand phulwani
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
first of all its better to be on one thread rather than posting the same on multiple.


You must probably be knowing Anand that assignment statements are evaluated from left to right.
if
i=0;

so here
k=i++;
1) i is evaluated first which results in 0
2) Value of i taken in buffer (we can consider so) ie. 0
3) then increment i by 1 resulting in value of i being 1;
4) Buffered value is assigned to k;

and all this according to precedence.



see if this go according to precedence then how i should evaluate
k=i++;
1)++ has higher precedence evalate it
2)= has the lowest precedence, so number assigned.
(i think we can use no instead of number,this is a general english abbrevation which is not restricted,but still if someone is unable to understand i am happy to correct it)

which i know is wrong
rest Buffering Concept i am still searching to validate this.

[ September 16, 2005: Message edited by: anand phulwani ]
[ September 16, 2005: Message edited by: anand phulwani ]
 
Sandeep Chhabra
Ranch Hand
Posts: 340
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First of all Anand buffering concept was explinatory to give you a hint watz going back-stage.

secondly i told you assignment evaluations take place from left to right.

and i dont understand what do you mean by:
2)= has the lowest precedence so no assign

some experienced members of JavaRanch may surely help you and also correct me if i am wrong.

Sandy
 
anand phulwani
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually i am ready to accept this,if you say that its
not a guess and you are sure that this is what is going back staze.
i will be happy with that,otherwise the Ranchers Are always there for us.

Thanks,
With Regds,
Anand
reply
    Bookmark Topic Watch Topic
  • New Topic