Formal parameter: Difference between revisions
Jump to navigation
Jump to search
imported>Nick Johnson (Changed links to "Foo programming language" into "Foo (programming language)") |
imported>Subpagination Bot m (Add {{subpages}} and remove any categories (details)) |
||
Line 1: | Line 1: | ||
{{subpages}} | |||
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 [[C (programming language)|C]], | 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 [[C (programming language)|C]], | ||
Line 16: | Line 18: | ||
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(). | 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(). | ||
Revision as of 11:58, 26 September 2007
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 C,
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().