This week's book giveaway is in the Testing forum.We're giving away four copies of The Way of the Web Tester: A Beginner's Guide to Automating Tests and have Jonathan Rasmusson on-line!See this thread for details.
Win a copy of The Way of the Web Tester: A Beginner's Guide to Automating Tests this week in the Testing forum!

# What is the follow of this code?

rex tony
Ranch Hand
Posts: 159
class C{
static int f1(int i) {
System.out.print(i + ",");
return 0;
}
public static void main (String[] args) {
int i = 0;
i = i++ + f1(i);
System.out.print(i);
}}

What is the follow of this code?

abhishek pendkay
Ranch Hand
Posts: 184
your question is not clear... the answer 1,0 is correct what is it that you want to know about the program...??

Ram Reddy
Ranch Hand
Posts: 88
hi tony,

following is the sequence of execution for

int i = 0;
i = i++ + f1(i);

i++ --> I value is substituted for expresseion (0), and i value is incremented . so i value is 1.

f1(i) -- > f1(1) is passed , which is returning 0.

but i = 0 + 0 . so the result is i =0 will be printed.

Kishore Kumar
Ranch Hand
Posts: 71
i = 0
i = i++ + f1(i) is evaluated as:
i = 0 + f1(i) //i value(0) is used first. And then i is incremented to 1
i = 0 + f1(1) // i = 1 here.
f1(1) function is called. So 1 is printed. and 0 is returned.
now i = 0 + 0(returned value from f1(int) function)
so, i = 0
Finally you are printing the value of i which is 0.

i hope i explained clearly..

rex tony
Ranch Hand
Posts: 159
Hello kesava narayana
1st i wanna thanks ,cause really i understand that program follow thor your explanation.