問題:
I am just wondering if there would be any loss of speed or efficiency if you did something like this:我只是想知道如果你做這樣的事情是否會降低速度或效率:
int i = 0;
while(i < 100)
{
int var = 4;
i++;
}
which declares int var
one hundred times.它聲明瞭int var
一百次。 It seems to me like there would be, but I'm not sure.在我看來好像會有,但我不確定。 would it be more practical/faster to do this instead:這樣做會更實用/更快嗎:
int i = 0;
int var;
while(i < 100)
{
var = 4;
i++;
}
or are they the same, speedwise and efficiency-wise?或者它們在速度和效率方面是否相同?
解決方案:
參考一: https://en.stackoom.com/question/47iF參考二: https://stackoom.com/question/47iF