These is no diffrence in running time. But the C++ draft suggest us to declare variable inside the loop as much as possible. and that is why C++ compiler can optimize on memory. And You should know that in C/C++ local variable alocated in stack, but sometimes there is some cost of changeing between memory farmes. So declaring a variable inside a loop is much easier and safer.