Here is a listing of basic C questions on “Break and Continue” along with answers, explanations and/or solutions:
1. What will be the output of the following C code?
-
#include
-
void main()
-
{
-
int i = 0;
-
if (i == 0)
-
{
-
printf("Hello");
-
continue;
-
}
-
}
a) Hello is printed infinite times
b) Hello
c) Varies
d) Compile time error
Answer: d
Clarification: None.
2. What will be the output of the following C code?
-
#include
-
void main()
-
{
-
int i = 0;
-
if (i == 0)
-
{
-
printf("Hello");
-
break;
-
}
-
}
a) Hello is printed infinite times
b) Hello
c) Varies
d) Compile time error
Answer: d
Clarification: None.
3. What will be the output of the following C code?
-
#include
-
int main()
-
{
-
int i = 0;
-
do
-
{
-
i++;
-
if (i == 2)
-
continue;
-
printf("In while loop ");
-
} while (i < 2);
-
printf("%dn", i);
-
}
a) In while loop 2
b) In while loop in while loop 3
c) In while loop 3
d) Infinite loop
Answer: a
Clarification: None.
4. What will be the output of the following C code?
-
#include
-
int main()
-
{
-
int i = 0, j = 0;
-
for (i; i < 2; i++){
-
for (j = 0; j < 3; j++)
-
{
-
printf("1n");
-
break;
-
}
-
printf("2n");
-
}
-
printf("after loopn");
-
}
a)
b)
c)
d)
View Answer
Answer: c
Clarification: None.
5. What will be the output of the following C code?
-
#include
-
int main()
-
{
-
int i = 0;
-
while (i < 2)
-
{
-
if (i == 1)
-
break;
-
i++;
-
if (i == 1)
-
continue;
-
printf("In while loopn");
-
}
-
printf("After loopn");
-
}
a)
In while loop After loop
b) After loop
c)
In while loop In while loop After loop
d) In while loop
Answer: b
Clarification: None.
6. What will be the output of the following C code?
-
#include
-
int main()
-
{
-
int i = 0;
-
char c = 'a';
-
while (i < 2)
-
{
-
i++;
-
switch (c)
-
{
-
case 'a':
-
printf("%c ", c);
-
break;
-
break;
-
}
-
}
-
printf("after loopn");
-
}
a) a after loop
b) a a after loop
c) after loop
d) error
Answer: b
Clarification: None.
7. What will be the output of the following C code?
-
#include
-
int main()
-
{
-
printf("before continue ");
-
continue;
-
printf("after continuen");
-
}
a) Before continue after continue
b) Before continue
c) After continue
d) Compile time error
Answer: d
Clarification: None.