What's the difference between "out" and "inout"?

Hasan Aljudy hasan.aljudy at gmail.com
Sun May 21 01:05:27 PDT 2006


Interesting, but why? What situations need this kind of behaviour?

Unknown W. Brackets wrote:
> There's a big difference:
> 
> out initializes the variable to the default initializer.
> inout does not change the value passed in.
> 
> Example:
> 
> import std.stdio;
> 
> int foo1(out i)
> {
>    writefln(i);
> }
> 
> int foo2(inout i)
> {
>    writefln(i);
> }
> 
> int main()
> {
>    int i;
> 
>    i = 5;
>    foo1(i);
> 
>    i = 5;
>    foo2(i);
> 
>    return 0;
> }
> 
> Will output:
> 
> 0
> 5
> 
> Because in the first case i is set to 0 because it is an int.  Out means 
> that the value before the call doesn't matter; with inout it may matter.
> 
> -[Unknown]
> 
> 
>> Maybe a silly question, but what's the difference bebtween "out" 
>> parameters and "inout" parameters?
>> For a long time I was under the impression that there's no difference 
>> ..  but I'm not sure anymore.



More information about the Digitalmars-d-learn mailing list