1.
#include “stdio.h”
int main()
{
int i;
for (i = 9; i!=0; i–)
printf(“i = %d”, i–);
return 0;
}
(a) 9 7 5 3 1
(b) 9 8 7 6 5 4 3 2 1
(c) Infinite Loop
(d) 9 7 5 3
2.
#include “stdio.h”
int main()
{
int A = 10, B = 20;
do {
B /= A;
} while(A–);
printf (“%d\n”, B);
return 0;
}
(a) 1
(b) Runtime Error
(c) 0
(d) Compiler Error
Answer
3.
#include “stdio.h”
int main()
{
int i = -8;
while (i <= 8) { if (i >= 0)
break;
else
{
i++;
continue;
}
printf(“BHOPAL”);
}
return 0;
}
(a) 10 times
(b) 8 times
(c) Infinite times
(d) 0 times
Answer
4.
#include “stdio.h”
int main()
{
int i = 3;
while (i–)
{
int i = 20;
i–;
printf(“%d “, i);
}
return 0;
}
(a) Infinite Loop
(b) 19 19 19
(c) 19 18 17
(d) 2 2 2
And i== just after declaration statement int i=20; changes local i of while loop.
5.
#include “stdio.h”
int main()
{
int i;
for (i = 1; i != 10; i += 2)
printf(” SCABHOPAl “);
return 0;
}
(a) SCABHOPAl SCABHOPAl SCABHOPAl ……… Infinite
(b) SCABHOPAl SCABHOPAl SCABHOPAl SCABHOPAl
(c) SCABHOPAl SCABHOPAl SCABHOPAl SCABHOPAl SCABHOPAl
(d) SCABHOPAl
6.
#include “stdio.h”
int main()
{
int x = 3;
if (x == 2); x = 0;
if (x == 3) x++;
else x += 2;
printf(“x = %d”, x);
return 0;
}
(a) x = 4
(b) x = 2
(c) Compiler Error
(d) x = 0
Answer
7.
#include “stdio.h”
int main()
{
int i = 1, j;
for ( ; ; )
{
if (i)
j = –i;
if (j < 10)
printf(“SCABHOPAL”, j++);
else
break;
}
return 0;
}
(A) Compile Error.
(B) No compile error but it will run into infinite loop printing SCABHOPAL.
(C) No compile error and it’ll print SCABHOPAL 10 times.
(D) No compile error but it’ll print SCABHOPAL 9 times.
Answer
8.
#include
int a();
int main(){
for(a();a();a()) {
printf(“%d “,a());
}
return 0;
}
int a(){
int static n=7;
return n–;
}
(a) 6 4
(b) 5 2
(c) Infinite loop with garbage value
(d) 7 5
Answer
First iteration:
Loop initial value: a() = 7
Loop condition: a() = 6
Since condition is true so printf function will print a() i.e. 5
Loop incrimination: a() = 4
Second iteration:
Loop condition: a() = 3
Since condition is true so printf function will print a() i.e. 2
Loop incrimination: a() = 1
Third iteration:
Loop condition: a() = 0
Since condition is false so program control will come out of the for loop.
9.
#include “stdio.h”
int main(){
static int a;
for(++a;++a;++a) {
printf(“%d “,a);
if(a==4) break;
}
return 0;
}
(a) 4
(b) Compile error: a is not referenced
(c) 2 4
(d) None of the above.
Answer
of variable a = 0
First iteration:
For loop starts value: ++a i.e. a= 0 + 1 = 1
For loop condition: ++a i.e. a = 1 + 1 = 2 i.e. loop condition is
true. Hence printf statement will print 2
Loop incrimination: ++a i.e. a = 2 + 1 =3
Second iteration:
For loop condition: ++a i.e. a = 3 + 1 = 4 i.e. loop condition is
true. Hence printf statement will print 4.
Since is equal to for so if condition is also true. But due to
break keyword program control will come out of the for loop.
10.
#include “stdio.h”
int main(){
for(;;) {
printf(“%d “,67);
}
return 0;
}
(a) Infinite loop
(b) 67
(c) Compilation error: declaration not done
(d) None
Answer
condition then it will take increment condition as Infinite.