R
rahul.batra
This is supposed to be a very general question.
Consider the following 2 code samples:
Code Sample 1:
for (int i=0; i<n; ++i)
{
for (int j=0; j<n; ++j)
{
/* Do something here */
}
}
Code Sample 2:
(Now we declare j in advance rather than each time inside the i loop
as in code sample 1)
int j;
for (int i=0; i<n; ++i)
{
for (j=0; j<n; ++j) // Notice the differnce here, now
{
/* Do something here */
}
}
Is code sample 2 faster than code sample 1?
Plz specify the reasons too.
Consider the following 2 code samples:
Code Sample 1:
for (int i=0; i<n; ++i)
{
for (int j=0; j<n; ++j)
{
/* Do something here */
}
}
Code Sample 2:
(Now we declare j in advance rather than each time inside the i loop
as in code sample 1)
int j;
for (int i=0; i<n; ++i)
{
for (j=0; j<n; ++j) // Notice the differnce here, now
{
/* Do something here */
}
}
Is code sample 2 faster than code sample 1?
Plz specify the reasons too.