Jump to

v01-l3-findOutput

What does this code produce

void divideBy(double& x, const int& div) {
    x /= div;
}

int main() {
    double x = 3;
    double div = 2.5;
    divideBy(x, div);
    cout << x << endl;
}

???

It is allowed to store an rvalue in a constant lvalue reference. So putting 2.5 in argument is similar as doing this at the initialization of the function scope :

const int& div = 2.5;

which simply round down the value so it can be stored into an int so the actual value of div is then 2 in the function.