C Programming :: Declarations and Initializations - Discussion
29 / 54
#include<stdio.h>
void main ( )
{
int i;
for( i=0; i<10; i++,printf("%d", i));
}
#include<stdio.h>
void main ( )
{
int i;
for( i=0; i<10; i++,printf("%d", i));
}
A2345678910
B123456789
CCompilation Error
D12345678910
Show Explanation
Now, let's dry run this particular code-
Value of i Condition(i<10) Updation Status
i=0 True i=0+1=1 1 gets printed
i=1 True i=1+1=2 2 gets printed
i=2 True i=2+1=3 3 gets printed
i=3 True i=3+1=4 4 gets printed
i=4 True i=4+1=5 5 gets printed
i=5 True i=5+1=6 6 gets printed
i=6 True i=6+1=7 7 gets printed
i=7 True i=7+1=8 8 gets printed
i=8 True i=8+1=9 9 gets printed
i=9 True i=9+1=10 10 gets printed
i=10 False -- --
Hence, the output will be 12345678910.
Asked In ::
In a for loop, first the initialization part is checked, then the test condition. If the test condition is true then the body of the loop gets executed. Then, updation part is done, again the test condition is checked. If true then again the body gets executed, and this process goes on until the test condition becomes false.
Now, let's dry run this particular code-
Value of i Condition(i<10) Updation Status
i=0 True i=0+1=1 1 gets printed
i=1 True i=1+1=2 2 gets printed
i=2 True i=2+1=3 3 gets printed
i=3 True i=3+1=4 4 gets printed
i=4 True i=4+1=5 5 gets printed
i=5 True i=5+1=6 6 gets printed
i=6 True i=6+1=7 7 gets printed
i=7 True i=7+1=8 8 gets printed
i=8 True i=8+1=9 9 gets printed
i=9 True i=9+1=10 10 gets printed
i=10 False -- --
Hence, the output will be 12345678910.
Read Full Answer
Report Error
Please Login First Click Here