The function declaration void test(double &r)
specifies that the argument is passed by reference not as a pointer. To pass a "pointer-to-double" use: void test(double *r)
.
Although, in practice, the effect is very similar, when passing an argument by reference, you don't explicitly give the address; so, in your code, the call should be as shown below. Also, as noted in the answer given by Vettri, your function does not return a double
value (or, indeed, anything, as it is void
), so you can't assign the variable yo
directly from the call to it.
Try this, as one possible solution:
test(rdefined); // Changes the value of "rdefined"
double yo = rdefined; // Assigns modified value to "yo"
For a discussion on the differences between pointers and references, see here.