开发者

In parameter-passing by result, when the formal parameter value is assigned to the actual one?

As title, just after return statement?

int x = 1;

function F(ref int y) { y  = y + AnotherF(x); }

function A开发者_开发知识库notherF(result z)
{
   z = null;
   return (-1);
}

F(x); print(x); // prints 0 or null?


Answer to myself: The function AnotherF returns -1. The just before destroying its record (and thus before passing the control back to F), the value of z is assigned back to the actual parameter (y). After assigning null to x then F continues to evaluate y = 1 + (-1) = 0. Then x is 0.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜