# Questions about Function calls..

• 07-27-2004
RealityFusion
Questions about Function calls..
I am continuing my reading in deitle/deitle. In chapter 3 it is explaining functions to me. My question is why are the parameters named different? This is how it calls the function:
(All the numbers are of type double)
Code:

`cout << maximum ( number1, number2, number3 ) <<endl;`
In the function definition, they have it set up like this:
Code:

`double maximum (double x, double y, double z)`
In the function they are not returning x,y or z. They are returning the largest number of number1, number2, and number 3. To me it looks like the function call passes number1, number2, number3 and recieves x,y and z?!?!?

My question is, why are the variables in the parameters different? When I read about it, I think they are saying that they are different because of something programmers use called signatures? I am really confused on this one...can anyone help me out?
• 07-27-2004
Thantos
Its all about scoping. number1, number2, number3 only exist in their function. x, y, z exist only in their function. When you call a function you make a copy of the number1, number2, and number3 which are then given to maximum() which calls them x, y, z. They are different because they can be and different names might make more sense.
• 07-28-2004
jlou
In addition to what Thantos said, the function maximum doesn't know anything about the code that calls it. It doesn't care. It just says, "Give me three doubles, I'll name them whatever I want - maybe I'll name them x, y and z." The code that calls the maximum function doesn't care what that function will call the numbers. It says, "I have three doubles that I am calling number1, number2 and number3. I want to find the maximum, so I'll send these doubles to the maximum function."

That is what Thantos is referring to by scope. Each part of the program doesn't care what the variables in the other part of the program are called. To see why this is important, add a couple more variables - number4 and number5 - and then try to find the maximum of number1, number2 and number3, then number 2, number 3, and number4, and so on. If the variable names were the same in the function, how would that work?