Formal parameter: Difference between revisions

From Citizendium
Jump to navigation Jump to search
imported>Nick Johnson
No edit summary
 
mNo edit summary
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
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]],
{{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]],


<code>
<code>
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().[[Category:Suggestion Bot Tag]]
 
[[Category: Computers Workgroup]]
[[Category: CZ Live]]

Latest revision as of 16:01, 17 August 2024

This article is a stub and thus not approved.
Main Article
Discussion
Definition [?]
Related Articles  [?]
Bibliography  [?]
External Links  [?]
Citable Version  [?]
 
This editable Main Article is under development and subject to a disclaimer.

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().