What is an argument? Differentiate between formal arguments and actual arguments?

28 Dec 2022 Balmiki Mandal 0 C Programming

Understanding Formal and Actual Arguments in Programming

In computer programming, the term "argument" refers to a value or expression that is provided to a function or program when it is called or invoked. Arguments are essential for passing data into functions or programs so that they can perform their tasks with the necessary input. There are two main types of arguments in C programming: formal arguments and actual arguments (also known as formal parameters and actual parameters).

Formal Arguments (Formal Parameters):

  • Formal arguments, also called formal parameters, are placeholders or variables declared within the function's definition.
  • These parameters specify the data type and name of the values that the function expects to receive when it is called.
  • Formal arguments are used to define the interface of a function, indicating what type and how many values the function requires to work correctly.
  • They act as local variables within the function and are initialized with the values passed as actual arguments when the function is called.
  • Formal arguments are used to define the function's signature and are enclosed in the parentheses of the function declaration.

Example:

C Programming
void add(int x, int y) {
    int sum = x + y;
    printf("Sum: %d\n", sum);
}

In the function add, x and y are formal arguments (formal parameters).

Actual Arguments (Actual Parameters):

  • Actual arguments, also known as actual parameters, are the values or expressions that are passed to a function when it is called.
  • These values are provided in the function call and are used to initialize the formal arguments of the function.
  • Actual arguments can be constants, variables, expressions, or the results of other function calls.
  • They must match the data types and order of the formal arguments in the function declaration.
C Programming
int main() {
    int a = 5, b = 3;
    add(a, b); // Here, 'a' and 'b' are actual arguments.
    return 0;
}

 

In the add(a, b) function call, a and b are actual arguments that correspond to the formal parameters x and y in the add function.

In summary, formal arguments are the parameters declared in a function's definition, specifying the types and names of values the function expects to receive, while actual arguments are the values provided in a function call to initialize the formal arguments. This distinction is crucial for understanding how functions work in C programming and how data is passed between different parts of a program.

BY: Balmiki Mandal

Related Blogs

Post Comments.

Login to Post a Comment

No comments yet, Be the first to comment.