I didn't quite get the explanation in our book which was " In a car, there are pedals, a wheel..blah blah and an accelerator... In C++ a parameter is like an accelerator...it tells the car how fast to accelerate.."
I totally didn't get it...and the word "parameter" keeps popping up in the succeeding chapters....
Could someone explain to me what a parameter is?
That book has a problem with the analogy. A parameter is not so much the gas pedal as it is how much strength you apply on it.
1 2 3 4 5 6 7 8 9 10 11 12 13 14
/*
a and b are the formal parameters of sum() (i.e. the parameters sum() is
declared to expect).
*/
int sum(int a,int b){
return a+b;
}
//...
/*
Here, 1 and 2 are the actual parameters being passed to sum(). These values are
assigned to each of the function's formal parameters. In this case, a is
assigned 1 and b is assigned 2.
*/
int a=sum(1,2);