What's the difference between "out" and "inout"?
Lionello Lunesu
lionello at lunesu.remove.com
Sun May 21 03:38:38 PDT 2006
I think you should look at "out" as if it were the function's return value:
#void func(out int i) { return i; }
#int func() { int i; return i; }
I think these two should behave the same way. In fact, they do :)
L.
"Hasan Aljudy" <hasan.aljudy at gmail.com> wrote in message
news:e4p6vo$1kmn$1 at digitaldaemon.com...
> 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