just want to ask what the differences are between variables declarations/definitions inside or outside of a loop/if/switch-case etc. for example:
int a, b, c;
unsigned i;
for( i=0; i<100; i++ )
{
a = ...;
b = ...;
c = ...;
}
and
for( unsigned i=0; i<100; i++)
{
int a = ...;
int b = ...;
int c = ...;
}
I am guessing there are no differences between those two; the compiler will create the same code for both?
I am asking because the latter approach (declaring/defining variables inside loop/if/switch etc.) may look clearer and reduce the number of variable declarations/definitions at the beginning of the function. ( assuming there are a significant number of variables (>10) used in a function, declaring them all at the beginning may look very messy.
could you please give some suggestions and what is the best way in practice?