| Author |
test example on pre increment and post increment operator
|
ragi singh
Ranch Hand
Joined: Mar 10, 2010
Posts: 198
|
|
hi all
I have a question
Q. Find the output :-
class Compound{
public static void main(String args[])
{
int k=12;
k/=--k;
System.out.println(k);
k*=k++; //Line1
System.out.println(k);
k*=++k; //Line2
System.out.println(k);
}
}
Output is :- 1 1 2
acn anyone explain what happens at line 1 and line 2
|
 |
Martin Vanyavchich
Ranch Hand
Joined: Sep 16, 2008
Posts: 241
|
|
|
Take a look at this
|
SCJP 6, OCMJD 6, OCPJWSD 6
I no good English.
|
 |
Harshit Sethi
Ranch Hand
Joined: Jul 16, 2010
Posts: 75
|
|
|
Someone expalin this code's output why not the second SOP gives 2 as output???
|
 |
Martin Vanyavchich
Ranch Hand
Joined: Sep 16, 2008
Posts: 241
|
|
Hope it helped
|
 |
ragi singh
Ranch Hand
Joined: Mar 10, 2010
Posts: 198
|
|
Thanks for your post . it helped me especially the article
Post Increment Operator And Assignment
|
 |
Harshit Sethi
Ranch Hand
Joined: Jul 16, 2010
Posts: 75
|
|
|
But i still have one doubt when the value ++k in k*=++k rewriting it as k=k*(++k); is incremented first then why not the first k on the right hand side of = also gets incremented ???
|
 |
 |
|
|
subject: test example on pre increment and post increment operator
|
|
|