<I>Chance Favours the Prepared minds"</I>
<I>Chance Favours the Prepared minds"</I>
I agree with u Rajiv Ranjan But kan some 1 pls explain me as to how i+++i++ work ie
i = 5;
i = i+++i++
then i becomes 11 HOW??
and how far kan we use it can we write i++++i++i++++i++i--.......
Also 1 more thing
byte fff = 4;
fff = fff++;
System.out.println("fff is " +fff);
out put is amazingly 4
and
byte fff = 4;
fff++;
System.out.println("fff is " +fff);
produces 4
kan some i explain this also
AMIT
<I>Chance Favours the Prepared minds"</I>
<I>Chance Favours the Prepared minds"</I>
public static void main(String args[])
{
int i = 5;
i = i+++i++; // same as i = i++ + i++
System.out.println("i = "+i);
int a = 5;
int b = 5;
int c = a+++b++; // same as c = a++ + b++
System.out.println("a = "+a);
System.out.println("b = "+b);
System.out.println("c = "+c);
}
}
<I>Chance Favours the Prepared minds"</I>
These operators modify value of an expression by adding or sutracting by 1.
So for example in an <code>int</code> variable <code>x</code> contains 10, <code>--x</code> gives value of 9. Since in this case the expression --x itself describes the storage(the value of variable x) the resulting value is stored in x.
.....
.....
Let us look more closely at how the position of these operators affects their behaviour. If the operator preceds the expression,then the value of expression is modified before it takes part in the the rest of the calculation.this is called pre-increment or pre-decrement. Conversely, if the operator is positioned to the right of an expression, then the value that is used in the rest of the calculation is the original value of that expression and the increment or decrement only occcurs after the exression has been calulated.
Conversely, if the operator is positioned to the right of an expression, then the value that is used in the rest of the calculation is the original value of that expression and the increment or decrement only occcurs after the exression has been calulated.
The result of the postfix increment expression is not a variable, but a value.
<I>Chance Favours the Prepared minds"</I>
<I>Chance Favours the Prepared minds"</I>
In both the case the value of the expression evaluates to be true, the value of x before increment, being 0, is returned and then x is incremented while in case of y, the value of y is first incremented and then returned, i.e. 1 is returned.
No doubts about what kind of value is returned by x and y respectively. But the query I've is the value shown by
System.out.println(" x = "+x);
It is understood that from x = (b1 | b2)?x++:--x ; x is assigned the value of 0, but my question is that after returning value, x does get incremented to 1.
SO WHERE DOES THIS VALUE GO ???
Why System.out.println(" x = "+x); should show the assigned value of x NOT the incremented value of x.
Uncontrolled vocabularies
"I try my best to make *all* my posts nice, even when I feel upset" -- Philippe Maquet