What does program do when array is returned from function?
Daniel Kozák via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Jun 4 00:20:11 PDT 2015
On Thu, 04 Jun 2015 07:03:30 +0000
tcak via Digitalmars-d-learn <digitalmars-d-learn at puremagic.com> wrote:
> [code]
> char[] test(){
> auto t = new char[5];
>
> return t;
> }
> [/code]
>
> Is the test function returning just a pointer from heap or does
> copy operation?
>
this is same as:
auto t = new char[](5)
it will return array(which is struct with pointer to data and size)
> It is not obvious what it does, and I am trying to avoid doing
> this always.
there is no reason.
But be carefull, this could be wrong
[code]
char[] test(){
char[5] t;
return t;
}
[/code]
More information about the Digitalmars-d-learn
mailing list