So I have an application which does quite a lot of math, therefore there's a big amount temp variables. The thing I'm wondering: is there any performance difference when I declare variable before a loop and then reuse it (code 1), or is it better to declare it inside the loop (code 2)? The variable is needed only inside the loop and the n
can be up to tens of thousands. Or is it better to have them as global variables? The loop is also called more than once.
code 1:
double temp;
for (int i = 0; i < n; i++) {
temp = ...;
}
code 2:
for (int i = 0; i < n; i++) {
double temp = ...;
}
Thanks for tips.