A
aaragon
Hi everyone,
I just wanted to know if there is any difference in performance in
declarating the variables in the beginning of a function or within for
loops. For example:
double test()
{
double a,b,c;
for(int i=0; i<n; i++){
a = i*10;
b = a-i;
c += a*b;
}
return c;
}
or:
double test()
{
double c;
for(int i=0; i<n; i++){
double a = i*10;
double b = a-i;
c += a*b;
}
return c;
}
I just wanted to know if there is any difference in performance in
declarating the variables in the beginning of a function or within for
loops. For example:
double test()
{
double a,b,c;
for(int i=0; i<n; i++){
a = i*10;
b = a-i;
c += a*b;
}
return c;
}
or:
double test()
{
double c;
for(int i=0; i<n; i++){
double a = i*10;
double b = a-i;
c += a*b;
}
return c;
}