Void function?

I'm struggling to figure out why in the output, r == 2 j == 3 k == 2
r == 10 j == 2 k == 3, why the second time r would be equal to 10. Can anyone tell me why?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
void func9() {
 
	cout << "func9() " << endl;
 
	int doSomething( int &, int  );
 
        int j = 2;
        int k = 2;
        int r = j++;
 
        cout << "r == " << r << " j == " << j << " k == " << k << endl;
 
        r = doSomething(j, ++k);
 
        cout << "r == " << r << " j == " << j << " k == " << k << endl;
}
 
int doSomething( int & f, int k ) {
        int j = f+k++;
 
	  f--;
 
        return(j+k);
}
hideous.
Use a debugger, inspect the variables (a watchpoint may be useful) and step by step execution.

It may help you change the names of the variables so they are all named differently.
Topic archived. No new replies allowed.