Formal parameters

From Citizendium
Revision as of 12:37, 11 April 2007 by imported>Nick Johnson
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

In computer science, a formal parameter is a name by which a subroutine refers to one of its parameters. This is not to be confused with an actual parameter, which is the name or value passed to the function by the caller. For example, in the C programming language,

int foo(int a)
{
   int b = 5;

   return a + b;
}

int bar(void)
{
   return foo(1);
}


The subroutine bar() calls foo(). When bar() calls foo(), it passes the constant 1. Within bar(), 1 is an actual parameter to foo(). Within foo(), a is a formal parameter which references the actual parameter 1 from bar().