Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Parameter (computer programming)
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===Use=== The primary use of output parameters is to return multiple values from a function, while the use of input/output parameters is to modify state using parameter passing (rather than by shared environment, as in global variables). An important use of returning multiple values is to solve the [[semipredicate problem]] of returning both a value and an error status β see [[Semipredicate problem#Multivalued return|Semipredicate problem: Multivalued return]]. For example, to return two variables from a function in C, one may write: <syntaxhighlight lang="c"> int width int height; F(x, &width, &height); </syntaxhighlight> where <code>x</code> is an input parameter and <code>width</code> and <code>height</code> are output parameters. A common use case in C and related languages is for [[exception handling]], where a function places the return value in an output variable, and returns a Boolean corresponding to whether the function succeeded or not. An archetypal example is the <code>TryParse</code> method in .NET, especially C#, which parses a string into an integer, returning <code>true</code> on success and <code>false</code> on failure. This has the following signature:<ref>[http://msdn.microsoft.com/en-us/library/f02979c7.aspx Int32.TryParse Method (String, Int32)]</ref> <syntaxhighlight lang="csharp"> public static bool TryParse(string s, out int result) </syntaxhighlight> and may be used as follows: <syntaxhighlight lang="csharp"> int result; if (!Int32.TryParse(s, result)) { // exception handling } </syntaxhighlight> Similar considerations apply to returning a value of one of several possible types, where the return value can specify the type and then value is stored in one of several output variables.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)