Simple loop, which one I would get more performance and which one is recommended? defining a variable inside a loop or outside of it?

Posted by Grego on Stack Overflow See other posts from Stack Overflow or by Grego
Published on 2012-04-03T22:31:30Z Indexed on 2012/04/03 23:29 UTC
Read the original article Hit count: 179

Filed under:
|
|

Variable outside of the loop

int number = 0;
for(int i = 0; i < 10000; i++){
     number = 3 * i;
     printf("%d",number);
}

or Variable inside of the loop

for(int i = 0; i < 10000; i++){
     int number = 3 * i;
     printf("%d",number);
}

Which one is recommended and which one is better in performance?

Edit:

This is just an example to exhibit what I mean, All I wanna know is if defining a variable inside a loop and outside a loop means the same thing , or there's a difference.

© Stack Overflow or respective owner

Related posts about c++

Related posts about c