references as inputs to a function

Hello every body,

Could any one help me in understanding the meaning of giving the references as the input of a function. The example is:
int boost_z (const double t, const double x , const double y , const double z, double& t_prime, double& x_prime , double& y_prime , double& z_prime , const double velocity)
{
The code for the function
}

int main()
{
//calling the function
int status =boost_z (t , x ,y ,z , t_prime , x_prime, y_prime , z_prime);
//the rest of the code
}

What I don't understand is what would happen if I didn't pass the memory address of the final 4 variables to the function?
I don't understand why in the code I just used their values!!!
Thak you in advance
If you send by reference, you can change the value of the variable (in main) inside the function. If you're not using a reference, it will just send a copy to the function, so if you change it there, it will have no effect on the variable in main.
Sorry, I don't understand. Could you pls give a more simpler definition.

t_prime , x_prime , y_prime and z_prime can get any value in the function either I pass their memory address or with out memory address.
unfortunately, the amperstand is overloaded in C++

1. sometimes, it is the address-of operator
2. other times, it means this variable is a reference

the two have absolutely nothing to do with each other!!!

for 1., as an address-of operation, it is the inverse operation of *, the de-reference operator (also overloaded against the arithmetic multiplication operator).
for 2., as the case is here, non-const reference arguments imply that you can expect boost_z() to modify the values of t_prime , x_prime , y_prime and z_prime inside the function boost_z()

that means, where you have the comment // the rest of the code
you can actually see the changes made in boost_z() when you look at t_prime , x_prime , y_prime and z_prime
Last edited on
Topic archived. No new replies allowed.