1. What is the output of this C code?
#include <stdio.h>
void main()
{
char *str = "";
do
{
printf("hello");
} while (str);
}
a) Nothing
b) Run time error
c) Varies
d) Hello is printed infinite times
View Answer
Answer:d
2. What is the output of this C code?
#include <stdio.h>
void main()
{
int i = 0;
while (i < 10)
{
i++;
printf("hi\n");
}
while (i < 8)
{
i++;
}
printf("hello\n");
}
a) Hi is printed 8 times, hello 7 times and then hi 2 times
b) Hi is printed 10 times, hello 1 times
c) Hi is printed once, hello 7 times
d) Hi is printed once, hello 7 times and then hi 2 times
View Answer
Answer:b
3. Example of iteration in C.
a) for
b) while
c) do-while
d) All of the mentioned
View Answer
Answer:d
4. Number of times while loop condition is tested is, i is initialized to 0 in both case.
while (i < n)
i++;
-------------
do
i++;
while (i <= n);
a) n, n
b) n, n+1
c) n+1, n
d) n+1, n+1
View Answer
Answer:d
5. What is the output of this C code?
#include <stdio.h>
int main()
{
int i = 0;
while (i = 0)
{
printf("True\n");
}
printf("False\n");
}
a) True (infinite time)
b) True (1 time) False
c) False
d) Compiler dependent
View Answer
Answer:c
6. What is the output of this C code?
#include <stdio.h>
int main()
{
int i = 0, j = 0;
while (i < 5 , j < 10)
{
i++;
j++;
}
printf("%d, %d\n", i, j);
}
a) 5, 5
b) 5, 10
c) 10, 10
d) Syntax error
View Answer
Answer:c
7. Which loop is most suitable to first perform the operation and then test the condition?
a) for loop
b) while loop
c) do-while loop
d) None of the mentioned
8.What is the output of this C code?
#include <stdio.h>
void main()
{
double k = 0;
for (k = 0.0; k < 3.0; k++)
{
}
printf("%lf", k);
}
a) 2.000000
b) 4.000000
c) 3.000000
d) Run time error
View Answer
Answer:c
9. What is the output of this C code?
#include <stdio.h>
void main()
{
int k;
for (k = -3; k < -5; k++)
{
printf("Hello");
}
printf("xyz");
}
a) Hello
b) Infinite hello
c) Run time error
d) Nothing
ans :d
10. What is the output of this C code?
#include <stdio.h>
int main()
{
int i = 0;
for ( ; ; )
{
printf("In for loop\n");
}
printf("After loop\n");
}
a) Compile time error
b) Infinite loop
c) After loop
d) Undefined behaviour
ans:c
11. What is the output of this C code?
#include <stdio.h>
int main()
{
int i = 0;
for (i++; i == 1; i = 2)
printf("In for loop ");
printf("After loop\n");
}
a) In for loop After loop
b) After loop
c) Compile time error
d) Undefined behaviour
ans:a
12. What is the output of this C code?
#include <stdio.h>
int main()
{
int i = 0;
for (foo(); i == 1; i = 2)
printf("In for loop\n");
printf("After loop\n");
}
int foo()
{
return 1;
}
a) After loop
b) In for loop after loop
c) Compile time error
d) Infinite loop
ans: a
13. What is the output of this C code?
#include <stdio.h>
int main()
{
int *p = NULL;
for (foo(); p; p = 0)
printf("In for loop\n");
printf("After loop\n");
}
a) In for loop after loop
b) Compile time error
c) Infinite loop
d) Depends on the value of NULL
ans:b
14. What is the output of this C code?
#include <stdio.h>
int main()
{
for (int i = 0;i < 1; i++)
printf("In for loop\n");
}
a) Compile time error
b) In for loop
c) Depends on the standard compiler implements
d) Depends on the compiler
ans : c
15. What is the output of this C code?
#include <stdio.h>
void main()
{
int k = 0;
for (k < 3; k++)
printf("Hello");
}
a) Compile time error
b) Hello is printed thrice
c) Nothing
d) Varies
Ans:a
16. What is the output of this C code?
#include <stdio.h>
void main()
{
int i = 5, k;
if (i == 0)
goto label;
label: printf("%d", i);
printf("Hey");
}
a) 5
b) Hey
c) 5 Hey
d) Nothing
Ans:c
17. What is the output of this C code?
#include <stdio.h>
int main()
{
printf("%d ", 1);
goto l1;
printf("%d ", 2);
l1:goto l2;
printf("%d ", 3);
l2:printf("%d ", 4);
}
a) 1 4
b) Compile time error
c) 1 2 4
d) 1 3 4
Ans:a
18. What is the output of this C code?
#include <stdio.h>
int main()
{
printf("%d ", 1);
l1:l2:
printf("%d ", 2);
printf("%d\n", 3);
}
a) Compile time error
b) 1 2 3
c) 1 2
d) 1 3
Ans:b
19. What is the output of this C code?
#include <stdio.h>
int main()
{
int i = 0, j = 0;
while (i < 2)
{
l1: i++;
while (j < 3)
{
printf("loop\n");
goto l1;
}
}
}
a) loop loop
b) Compile time error
c) loop loop loop loop
d) Infinite loop
Ans:d
20. What is the output of this C code?
#include <stdio.h>
int main()
{
while ()
printf("In while loop ");
printf("After loop\n");
}
a) In while loop after loop
b) After loop
c) Compile time error
d) Infinite loop
Ans:c