开发者

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

开发者 https://www.devze.com 2023-02-06 23:38 出处:网络
As title, just after return statement? int x = 1; function F(ref int y) { y= y + AnotherF(x); } function A开发者_开发知识库notherF(result z)

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

精彩评论

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