Please tell me the difference between an argument and parameter...i was really confused in understanding the difference between these two.
Difference between parameter and argument
Collapse
X
-
Tags: None
-
A parameter is a named value whereas an argument is just a value. For example:
Here int and char are parameters while x and y are arguments. The arguments can have any value. The parameter has to be an int.Code:int function(int x, char y);
Another example:
An enum list like this is a list of named integer values. RED, WHITE, and BLUE above are parameters with values 0,1, and 2. So of all the int values possible only 0,1 and 2 are valid. You use RED instead of 0, WHITE instead of 1, etc.Code:enum color = {RED, WHITE,BLUE}; -
The difference between parameter and argument is subtle: use the term parameter when referring to the function declaration or function/macro definition; use the term argument when referring to function/macro invocations. The modifiers suggested by the definitions can help to keep them straight: actual argument versus formal parameter.Excerpts from the 1999 C Standard (C99), Section 3 (Terms, definitions, and symbols)...
3.3 argument
actual argument
actual parameter (deprecated)
expression in the comma-separated list bounded by the parentheses in a function call expression, or a sequence of preprocessing tokens in the comma-separated list bounded by the parentheses in a function-like macro invocation.
3.15 parameter
formal parameter
formal argument (deprecated)
object declared as part of a function declaration or definition that acquires a value on entry to the function, or an identifier from the comma-separated list bounded by the parentheses immediately following the macro name in a function-like macro definition.
It looks like the terms were once interchangeable but that later versions of the Standard deprecated interchangeable use of the terms.Comment
-
Argument
An argument is referred to the values that are passed within a function when the function is called. These values are generally the source of the function that require the arguments during the process of execution. These values are assigned to the variables in the definition of the function that is called. The type of the values passed in the function is the same as that of the variables defined in the function definition. These are also called Actual arguments or Actual Parameters.
Example
ParametersCode:#include <stdio.h> int sum(int a, int b) { return a + b; } int main() { int num1 = 10, num2 = 20, res; res = sum(num1, num2); printf("The summation is %d", res); return 0; }
The parameter is referred to as the variables that are defined during a function declaration or definition. These variables are used to receive the arguments that are passed during a function call. These parameters within the function prototype are used during the execution of the function for which it is defined. These are also called Formal arguments or Formal Parameters.
Example
Code:#include <stdio.h> int Mult(int a, int b) { return a * b; } int main() { int num1 = 10, num2 = 20, res; res = Mult(num1, num2); printf("The multiplication is %d", res); return 0; }Comment
-
Hey,
A parameter is a named variable passed into a function. ... Note the difference between parameters and arguments: Function parameters are the names listed in the function's definition. Function arguments are the real values passed to the function
Difference between parameters and arguments:
- Function parameters are the names listed in the function's definition.
- Function arguments are the real values passed to the function.
- Parameters are initialized to the values of the arguments supplied.
for more information and Example refer following site:
Comment
-
Yeah, it's confusing for some beginners. Don't worry. I will help you out! A Parameter is a named variable passed into a function definition, whereas arguments are the real values passed to the function.Comment
Comment