Difference Between Arguments and Parameters in C

Learn via video course
FREE
View all courses
C++ Course: Learn the Essentials
C++ Course: Learn the Essentials
by Prateek Narang
1000
5
Start Learning
C++ Course: Learn the Essentials
C++ Course: Learn the Essentials
by Prateek Narang
1000
5
Start Learning
Topics Covered

Arguments and parameters are commonly used in various programming languages, and they are different. Arguments are the actual values supplied during a function call where Parameters act as placeholders to which the values of arguments are passed. Let's examine each of them individually.

What is Argument in C?

Arguments in C are the variables that are used to pass certain values. We use functions to reduce code complexity and improve readability in the C program. We create some user-defined functions which allow us to reuse the code.

When we create a function, we can pass the data in the form of an argument to the calling function. The passing data can be an integer value, floating-point value, etc. Arrays or strings can also be passed as data to other functions. What is Argument in C

Example Arguments

The above code is an example of argument passing in C. There are mainly two kinds of arguments.

  1. Argument with return value
  2. Argument without return value

This is an example of the first kind of argument, an Argument with a return value.

  • There is a main() function. We declare two variables first_number and second_number inside the main().
  • We also initialized with 4 and 6 values, respectively.
  • We declare one more variable sum to store the sum of two numbers. Assume that we have a user-defined function add(), which takes two numbers and produces the sum as its output.
  • We call the function add() and assign it to the variable sum.

Now the program's control is given to the first line of add(). After executing the statements of add(), the value is stored in the variable sum.

The variable sum holds the result and gets printed in the main().

In the above line, we call the function add() by passing two values, i.e., 4 and 6. Here the variables firstnumber and secondnumber act as the arguments. They pass the value to the called function through them. Arguments with Return Value

The above image represents the "Argument with return value".

  • There is a main() that passes values to function1() when called.
  • function1() performs the operations, produces the required result, and sends it back to main().
  • Then, further operations like printing the result can be done inside the main().

An example for Argument Without Return Value

Here the main function calls the add() by passing the arguments. The result is printed in the add() function rather than returning it.

Arguments Without Return Value

What is Parameter

The parameter in C refers to any declaration of variables within the parenthesis during the function declaration. These are listed in the function's definition, separated by commas. WHat is Parameter

Example of Parameter

In the above lines of code, we can see the function definition. The actual addition function is performed here in this add() function. In this case, add() receives the value from the main function and performs the addition operation using the "+" operator. The new variable c is declared to store the value of the result. It has int as a return type, hence it returns integer c to the main() function.

Difference Between Argument and Parameter in C

These are the some concluded difference points on arguments vs parameters from the above discussion.

ArgumentParameter
Also known as actual parametersAlso known as formal parameters
Arguments are used while calling the functionParameters are used during the declaration of the function
Argument is the actual value of this variable that gets passed to function.Parameter is variable in the declaration of the function.

Example This is the combined example of argument vs parameter. These first_number and second_number are the arguments, whereas the a and b are parameters.

Conclusion

  • We saw the difference between argument and parameter is that parameter is a variable defined during function declaration while arguments are the actual values.
  • While passing the arguments from one function to another, one must ensure that the number of arguments passed must be equal to that of parameters received.
  • If the number of parameters and arguments mismatches in calling and called function error may arise.
  • Meaning of Parameter and Argument may change according to different programming languages.
  • The one-liner takeaway from this discussion of argument vs parameter is that arguments are passed in the function call, and parameters are written inside the function declaration.

See Also: