Is there any overhead to declaring a variable within a loop? (C++)

Stack space for local variables is usually allocated in function scope. So no stack pointer adjustment happens inside the loop, just assigning 4 to var. Therefore these two snippets have the same overhead.

Leave a Comment