[問題] variable 的值已回收
code如下:
function res = test_nested_1
a = 1; b = 2; x = 0; y = 9;
fprintf('Before call to fun1:\n');
fprintf('a, b, x, y = %2d %2d %2d %2d\n', a, b, x, y);
x = fun1(x);
fprintf('\nAfter call to fun1:\n');
fprintf('a, b, x, y = %2d %2d %2d %2d\n', a, b, x, y);
function res = fun1(y)
fprintf('\nAt start of call to fun1:\n');
fprintf('a, b, x, y = %2d %2d %2d %2d\n', a, b, x, y);
y = y + 5;
a = a + 1;
res = y;
fprintf('\nAt end of call to fun1:\n');
fprintf('a, b, x, y = %2d %2d %2d %2d\n', a, b, x, y);
end
end
輸出如下:
>> test_nested_1
Before call to fun1:
a, b, x, y = 1 2 0 9
At start of call to fun1:
a, b, x, y = 1 2 0 0
At end of call to fun1:
a, b, x, y = 2 2 0 5
After call to fun1:
a, b, x, y = 2 2 5 9
請問為何最後的y是9呢?
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 118.169.85.44
→
06/28 15:49, , 1F
06/28 15:49, 1F
→
06/28 15:49, , 2F
06/28 15:49, 2F
→
06/28 15:50, , 3F
06/28 15:50, 3F
→
06/28 15:50, , 4F
06/28 15:50, 4F
MATLAB 近期熱門文章
PTT數位生活區 即時熱門文章