int i ; for ( i = 4 ; i <= 5 ; i = printf ( "\n%d", i ) ) ; i++ ; why this code showing output 2 2 2 2 2 2 2 2....infinitely???
if u run the only for statement ang ignore i++,then also it will give same output......i++ is just for confusion over there....my question is why it is showing 2 2 2 2 2 2....why not any other value???? as it is initialized to 4 it should show 4...im guesing but why 2????
you're assigning i the value of the printf statement, which is 2; 1 for printing the \n plus 1 for printing the %d as the value of i. if you remove the semi after the for loop, it would probably print the value of i after one iteration, but it's a guess. it's infinite because i is less than 5 on each test condition since its value is always re-assigned to that of the printf. to fix it, remove the assignment to printf .
if I remove the semicolon after the for loop it prints the value '3' infinitely ,it means that it prints the value of i after one iteration.