Assignment 5 Jan 2024
Assignment 5 Jan 2024
a) Error
b) I love C -- will be printed 6 times
c) I love C -- will be printed 3 times
d) I love C –will be printed 5 times
Solution: (c) I love C will be printed 3 times
a) 0
b) 1
c) No output
d) Compiler error
Solution: (d) Break statement is applicable in loop and switch statements. It is not allowed inside if
statement. Thus the program will show compiler error.
a) 5
b) 4
c) 1
d) No output
Solution: (d) As i is initialized as an integer variable, integer value of i after the operation (i=i+0.5) will be zero.
Thus, the loop will never be ended and the control will not come to the printf statement at all. So, nothing will be
printed.
}
return 0;
}
a) Syntax error
b) 0 1 2 3 4 5 6 7 8 9 10
c) 1 2 3 4 5 6 7 8 9 10
d) 0123456789
Solution: (c)
for(; ;) is possible in c, there is no need to place condition with in the for(), you can place condition within
the body of the loop. The ++i makes it printing from 1 to 10.
a) True
b) False
c) Both ‘True’ and ‘False’
d) Compilation error
Solution: (c) ‘a--’ post-increment the value of a. Thus, the if statement is executed as the value of a is
considered as 1 which is true. ‘++a’ pre-increment the value of a. Thus, the decremented value of a (which
is 0) is incremented first and then assigned. So, both the if statements are executed ad correspondingly both
True and False will be printed.
Solution: (b) The loop will be continued till any of the condition k<=4 or j<=3 is satisfied. So, the loop will be
executed 3 times. Thus, the value of k and j would be 7 and 4.
10. What will be the value of ‘i’ after the execution of the program below
#include <stdio.h>
int main()
{
int i=1,j;
for(j=0;j<=10;j+=i)
{
i=i+j;
}
return 0;
}
a) 10
b) 11
c) 12
d) 13
Solution: (d) The value of j will reach to 8 and i will be 13. In the next iteration, j will become 8+13=21 and the
condition inside for loop will be invalid, thus the compilation will come out of the loop. So, the value of i will be 13.