+ 1
Why the following loop prints 1 infinite time
#include <stdio.h> int main() { int i; for( i=1;i<=5;printf("%d\n",i)); i++; return 0; }
3 Respuestas
+ 1
Suman Singh
Only reason is that ' ; ' in c indicates termination.
Like wise here also ; at end of for loop indicates no more to execute inside the block.
so
First i=1
since I<=5
laterpart will be executed that is printf function.
since no increment infinite 1 will be printed
Hope you understand!
+ 1
Yes. Remove semicolon after for loop statement.
@Uday khan
I think there is typo in:
"Since no increament,"
Make "Since on increament....."
0
Suman Singh In simple words while iterating in for loop atlast in the incrementing section you have not mentioned by how many steps loop should get iterated.
Instead it has printf() statement which means compiler doesnt know when to stop ,it just goes on printing 1