For example, if I have a loop
for(int i = 0; i < N; i++) {
int a, b, c, d, e;
cin >> a >> b >> c >> d >> e;
foo(a, b, c, d, e);
}
or
int a, b, c, d, e;
for(int i = 0; i < N; i++) {
cin >> a >> b >> c >> d >> e;
foo(a, b, c, d, e);
}
which one should be faster? In the first case, I define the five variables inside the for loop, and in the second one, I define it outside.
I've seen posts that talk about "which is faster" such as Difference between declaring variables before or in loop?, but I'm not sure which one takes less memory.
I don't really care about the complexity, but rather the amount of memory used up in my program.
Obviously, in this case, it doesn't really matter, but what if I have a multi-dimensional for-loop and I have to define variables millions of times? Or, what if I define a large vector with many elements inside multiple times?
I apologize if this question is really simple, as I am new to c++. Any help would be greatly appreciated. Thanks guys.