+ 1
Arguments or parameters?
This is still confusing to me, whether I have to call them parameters or arguments. Learning PHP I read that: When you define a function, the variables that represent the values that will be passed to it for processing are called parameters. However, when you use a function, the value you pass to it is called an argument. Does this mean they are actually both the same and the only difference is in using the variables?
6 ответов
+ 4
The more precise terminologies are,
-- Formal parameters: These are merely variable (objects) lists inside a pair of parenthesis in front of the function name (as part of the function signature when defining it) informing the compiler the expected inputs of the function.
Example:
void f( int parameter_1, int parameter_2 ) {
// implementation goes here...
}
This tells us the function `f` would accept two integer input through "receiving arguments" that later on will happen by "calling" the function `f`, then the two parameters would get initialized by them to use in the body of `f()`.
-- Actual arguments: Actual values that must be passed to a function when calling it.
void f( int parameter_1, int parameter_2 ) {
// implementation goes here...
}
void g() {
int argument_1 = 1;
int argument_2 = 2;
f( argument_1, argument_2 ); // calling
}
+ 3
Parameters are defined when defining a function, but argument are made when you actually call the function
function A(num1, num2) -> parameters
A(2, 9) -> arguments
+ 3
parameter: a box
argument: what you put in there
+ 1
A simple example clarifies so much more than text only. Thank you!!
+ 1
Sometimes is necessary to know "technical words" in order to understand. That three words are math words: function, argument, parameters.
You will get use to it. Just keep researching.
Sometimes there is no need for examples because words are a good way to communicate ideas and concepts. This kind of situations are common in programming.
Happy coding!
+ 1
True. Thx Jonas!