+ 1

declaring variable inside/outside the loop which is better?

ex #1 while(condition) { int temp; ... } ex #2 int temp; while(condition) { ... } when temp is only used inside the loop, is there any difference between those two? if there is which is better example?

22nd Jan 2017, 1:59 PM
Choi Kwangjong
1 Odpowiedź
+ 5
If you declare it inside it becomes local and when loop ends it gets deleted, this can free-up memory but this int won't be accessible from outside…
22nd Jan 2017, 2:00 PM
Valen.H. ~
Valen.H. ~ - avatar