0
What is the output of this code and how in c language...?
static int i; for (++i;++i;++i){ printf("%d",i); if ( i == 4) break; }
5 Respostas
+ 3
Static int will share the same memory multiple times means always new value will be use if u set i value as a zero talking about the flow
initially the i value is zero then in loop ++i first part here value will be increase by 1 then it will check second part condition but in condition u have written ++i here again value will be increased so current value of i is 2 so 2 will be print on screen then it will check if condition herr condition false then it will jump into third statement of loop ++i herr again value will be increased now this time value will be 3 after that' again we have to check condition so in place of condition u have written ++i here again i will be increase and it will print 4 on screen then check if condition here condition are true 4==4 so loop will be break and final output will be 24
+ 5
Break is a exit statement if your condition will be matched and if u use break then it will exit same if u use continue then it will skip line
here when i==4 //i is 4
So 4==4 condition is true and u will be exit from loop if u wont use break then your loop will execute infinite times
+ 1
Oo I understand thanks a lot sir
+ 1
The output was 2 and 4, but it looked like 24 because nothing came between the 2 and the 4. Try to add space or line break after the %d specifier in printf() call and you'll notice that ...
printf( "%d ", i );
0
But I don't understand how output is 24
Loop is break when i==4