1. What will be the output of the following 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
2. What will be the output of the following 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 7 times
c) Hi is printed once, hello 7 times
d) Hi is printed once, hello 7 times and then hi 2 times
3. What is an example of iteration in C?
a) for
b) while
c) do-while
d) all of the mentioned
4. How many times while loop condition is tested in the following C code snippets, if i is initialized to 0 in both the cases?
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
5. What will be the output of the following 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
6. What will be the output of the following 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
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. Which keyword can be used for coming out of recursion?
a) break
b) return
c) exit
d) both break and return
9. What will be the output of the following C code?
#include < stdio.h >
int main()
{
int a = 0, i = 0, b;
for (i = 0;i < 5; i++)
{
a++;
continue;
}
}
a) 2
b) 3
c) 4
d) 5
10. What will be the output of the following C code?
#include < stdio.h >
int main()
{
int a = 0, i = 0, b;
for (i = 0;i < 5; i++)
{
a++;
if (i == 3)
break;
}
}
a) 1
b) 2
c) 3
d) 4