In modern C (AKA C99 or C11) there is a better option
for(int i = 0; i < len; i++)
{
for(int j = i; j < len; j++)
{
that is to directly declare the loop variables inside the for
-statement.
In simple cases as yours, there is no difference on any level, this will all compile to the same binary.
In more complicated cases, there might be one, since you would be "re-using" the same variable for different purposes. You can easily mix up things and drain an old value from a previous use into later, where you aren't expecting it.
Minor disgression: int
is in most cases not the right type for loop indices that speak of "length" or similar. Indices shouldn't be negative and the width of the type should be such you can capture the size of any object. Modern C has size_t
for that purpose.
To have that feature with gcc, you'd have to add the switch -std=c99
or use the executable name c99
. clang and many other compilers on POSIX machines comply to C99 per default.