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.
More Related Contents:
- Declaring variables inside loops, good practice or bad practice?
- How can I get out of the loop and continue the loop again?
- my first c++ program runtime is super long like 5 – 10 minutes on a fast CPU it's a very basic c++ program [closed]
- How to deal with c-string pointers [closed]
- Lowercase letters that did not appear in the array, in order [closed]
- C++ Reading an unknown number of integers to cin and outputting the sum
- Triple Nested For loop (C++) [closed]
- For loop with an array
- Loops in loops and increment staying at 0 in C++ [closed]
- C++ – How to clear variables after a while loop? [closed]
- c++ skipping the if and for loops?
- Don’t know how to add loop to my program…?
- When to use extern in C++
- Optimizing away a “while(1);” in C++0x
- How to generate different random numbers in a loop in C++?
- How can I loop through a C++ map of maps?
- For every character in string
- iterate vector, remove certain items as I go
- Why is initialization of a new variable by itself valid? [duplicate]
- Endless loop in C/C++ [closed]
- Precise thread sleep needed. Max 1ms error
- GetDIBits and loop through pixels using X, Y
- C++11 – declaring non-static data members as ‘auto’
- Can I declare variables of different types in the initialization of a for loop? [duplicate]
- Why does `int ;` compile fine in C, but not in C++?
- Is there ever a need for a “do {…} while ( )” loop?
- How does OpenMP handle nested loops?
- Reusing thread in loop c++
- What is the purpose of a declaration like int (x); or int (x) = 10;
- Does C have One Definition Rule like C++?