Actual arguments, Formal arguments - C-Tutorial

Latest

Friday, 11 November 2016

Actual arguments, Formal arguments

Actual arguments (or) Actual Parameters

The arguments that are passed in a function call are called actual arguments. These arguments are defined in the calling function.

Formal arguments (or) Formal Parameters

The formal arguments are the parameters/arguments in a function declaration. The scope of formal arguments is local to the function definition in which they are used. Formal arguments belong to the called function. Formal arguments are a copy of the actual arguments. A change in formal arguments would not be reflected in the actual arguments.

/* Demonstrating the actual and formal arguments */

#include <stdio.h>
int add(int, int); /* Function Prototype */
int main()
{
  int a = 10, b= 20, sum;

  /* a and b are actual arguments. They are the source
     of data. Caller program supplies the data to called
     function in form of actual arguments. */

  sum = add(a,b); /* function call */

  printf("Sum of %d and %d is: %d \n", a, b, sum);
}

/* a and b are formal parameters. They receive the values from
   actual arguments when this function is called. */

int add(int a, int b)
{
  return  a + b;
}

OUTPUT:

Sum of 10 and 20 is: 30

No comments:

Post a Comment