问题:
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