I thought the answer for this prob was 5, but it's 5432... why is that?
*9. What output does the following 'FOR' statement produce?
for (i = 5, j = i - 1; j = i - 1; i > 0, j > 0; --i, j = i - 1)
printf("%d", i);
I thought the answer for this prob was 5, but it's 5432... why is that?
*9. What output does the following 'FOR' statement produce?
for (i = 5, j = i - 1; j = i - 1; i > 0, j > 0; --i, j = i - 1)
printf("%d", i);
why is it an invalid for a loop?
for( ; ; ) //valid - notice there are 2 semi-colons
for( ; ; ; ) //invalid - 3 semi-colons
that's why
even though the loop is invalid considering its a loop it would print more then one result (since the arguments in it allow it to loop more then one)
thats why the result will never be 5 only
just out of curiosity , even if that code was right , whats the purpose of "j" in there , since it doesnt do anything
I can't answer you.
That loop won't even compile!!
a while loop with and statements should compile that. What is the point of j?
sorry, i mistyped the statement... it was:
for (i = 5, j = i - 1; i > 0, j > 0; --i, j = i - 1)
printf("%d", i);
>I thought the answer for this prob was 5, but it's 5432... why is that?
Because it's a loop, where i starts at 5 and is decremented each iteration. printf() is called within the loop, so it starts by outputing a 5, then a 4, and so on. It stops at 2 because of j being equal to zero when i becomes 1.
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
It does under mingw. What compiler are you using?That loop won't even compile!!
fyodor
a for statement with three semicolons will not compile under mingw.Originally posted by wherethehellismypwd
It does under mingw. What compiler are you using?
fyodor