Suppose we have a loop that iterates many times:
for (int i=0; i < 1000000; ++i) {
int s = 100;
s += i;
cout << s;
}
We are only using s inside the loop body, so ideally we'd like to declare it there so it won't pollute the enclosing namespace.
I'm wondering if there's any disadvantage to that. For example, will it incur a performance cost, because the program re-declares s on every iteration?
Aucun commentaire:
Enregistrer un commentaire