开发者

Is function's result always initialized? [duplicate]

开发者 https://www.devze.com 2023-02-19 10:51 出处:网络
This question already has answers here: 开发者_运维技巧 Closed 11 years ago. Possible Duplicate: What is the default value of Result in Delphi
This question already has answers here: 开发者_运维技巧 Closed 11 years ago.

Possible Duplicate:

What is the default value of Result in Delphi

Similar to this question, I now ask the following.

function Test:Boolean;
begin end;

Is the result value always guranteed to be false(0)? Integer values are not, so are booleans?


No, if you don't initialise a value type function result then it's value is undefined. It could be False (0), True (1), or indeed some other integer value.

You can view a function return variable in the same light as a local variable which of course need to be initialized before use.

The moral of the tale? Always initialize your function return values.

0

精彩评论

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