Pages

Tuesday, May 23, 2017

Formal Parameters

Parameters written in a function definition are called the Formal Parameters. If a function is designed to use arguments, it must declare variables which accept values passed through function arguments. These variables are called the formal parameters of the function. They are like local variables inside the function. As mentioned in the following program; they are declared after the function name inside parenthesis. Formal parameters are separated by comma in function definition.

int sum(int num1, int num2)
{
  int answer;
  answer = num1 + num2;
  return answer;
}


The function sum( ) has two formal parameters: num1 and num2. This function returns answer to the calling function. The formal parameters receive the value of the arguments passed to the function. Remember that that, as local variables, they are destroyed upon exit from the function.


No comments:

Post a Comment