Explain the output stepwise


int main(){

int i=1,j=1;

for( ; j; printf("%d %d \n", i,j))

j=i++ <=1;

return 0;


2 1
3 0

Please explain the output!

Firstly we have i and j equal to 1. The for loop for( ; j; printf("%d %d \n", i,j)) will print i and j until j is true i.e. not equal to 0. Inside the for loop, we post increment i so i now becomes 2 after that statement. Since it is post increment i will become 2 only after j=i++ <=1; statement and in this statement we check whether i is less than equal to 1. Since the condition is true, we save 1 in j. After this we will print i and j that are 2 and 1 respectively. Now for loop will run again since j is 1. This time though i is 2. So After post incrementing i, j will hold 0 (since 2>1). Then we will print i and j and after that for loop will not run because j is 0.

thank you very much… I already got the answer by looking it more carefully. Can u please help me with my new doubt?