Question: I have created a C++ program in order to test the functionality of passing parameters by reference for functions.

```
#include <iostream>

using namespace std;

int f(int &b) {
    b = b + 1;
    cout << b << endl;
    return b;
}

int main() {
    int t = 10;

    cout << f(t) << " " << t << endl;
    //cout << f(&t) << " " << t << endl;

    system("PAUSE");

    return 0;
}

```

Could you please explain to me why does this program won't affect the value of `t` after the execution of the `f` function? The `b` parameter in passed be reference, so I thought that it's value would change after the execution of the program because I am working with the actual variable from the main function, not a copy of it. In this case, I would expect it to be 11, but it's not affected by the execution of the program.

Why is this happening?

Answer: 
The value of `t` **does** get incremented. You'll see this if you split the output statement in two:

```
cout << f(t) << endl;
cout << t << endl;

```

With your original single output statement:

```
cout << f(t) << " " << t << endl;

```

the compiler is free to evaluate `t` **before** `f(t)`, producing in the output you're seeing. For more info, see [cout << order of call to functions it prints?](https://stackoverflow.com/questions/2129230/cout-order-of-call-to-functions-it-prints)
You're tripping over output order. As pointed out, `t` *does* get incremented, but you may be confusing yourself over the order of the output.

However, I like to sidetrack from questions a bit and try to figure out how to get people to understand not just the immediate problem but why they are having difficulty in the first place, and here it's pretty clear to me.

**You need to learn the debugger.**

By using one, you can step through your code and see the value of `t` at any given point and also see, with hardly any effort on your part, that it does indeed get incremented (including exactly when and how). You'll also just gain a much better understanding of how code works by tracing through it with a debugger including concepts like recursion.

I recommended you get started on this immediately, as it will open your eyes to how the code actually works without guessing your way through it with output statements.