C Programming Questions and Answers on Break and Continue for Freshers

1. Which keyword can be used for coming out of recursion?

a) break
b) return
c) exit
d) Both break and return
Answer: b
2. What is the output of this C code?

  1.     #include 
  2.     int main()
  3.     {
  4.         int a = 0, i = 0, b;
  5.         for (i = 0;i < 5; i++)
  6.         {
  7.             a++;
  8.             continue;
  9.         }
  10.     }
a) 2
b) 3
c) 4
d) 5
Answer: d
3. What is the output of this C code?

  1.     #include 
  2.     int main()
  3.     {
  4.         int a = 0, i = 0, b;
  5.         for (i = 0;i < 5; i++)
  6.         {
  7.             a++;
  8.             if (i == 3)
  9.                 break;
  10.         }
  11.     }
a) 1
b) 2
c) 3
d) 4
Answer: d
4. The keyword ‘break’ cannot be simply used within:

a) do-while
b) if-else
c) for
d) while
Answer: b
5. Which keyword is used to come out of a loop only for that iteration?

a) break
b) continue
c) return
d) none of the mentioned
Answer: b
6. What is the output of this C code?

  1.     #include 
  2.     void main()
  3.     {
  4.         int i = 0, j = 0;
  5.         for (i = 0;i < 5; i++)
  6.         {
  7.             for (j = 0;j < 4; j++)
  8.             {
  9.                 if (i > 1)
  10.                     break;
  11.             }
  12.             printf("Hi \n");
  13.         }
  14.     }
a) Hi is printed 5 times
b) Hi is printed 9 times
c) Hi is printed 7 times
d) Hi is printed 4 times
Answer: a
7. What is the output of this C code?

  1.     #include 
  2.     void main()
  3.     {
  4.         int i = 0;
  5.         int j = 0;
  6.         for (i = 0;i < 5; i++)
  7.         {
  8.             for (j = 0;j < 4; j++)
  9.             {
  10.                 if (i > 1)
  11.                     continue;
  12.                     printf("Hi \n");
  13.             }
  14.         }
  15.     }
a) Hi is printed 9 times
b) Hi is printed 8 times
c) Hi is printed 7 times
d) Hi is printed 6 times
Answer: b
8. What is the output of this C code?

  1.     #include 
  2.     void main()
  3.     {
  4.         int i = 0;
  5.         for (i = 0;i < 5; i++)
  6.             if (i < 4)
  7.             {
  8.                 printf("Hello");
  9.                 break;
  10.             }
  11.     }
a) Hello is printed 5 times
b) Hello is printed 4 times
c) Hello
d) Hello is printed 3 times
Answer: c
9. What is the output of this C code?

  1.     #include 
  2.     void main()
  3.     {
  4.         int i = 0;
  5.         if (i == 0)
  6.         {
  7.             printf("Hello");
  8.             continue;
  9.         }
  10.     }
a) Hello is printed infinite times
b) Hello
c) Varies
d) Compile time error
Answer: d
10. What is the output of this C code?

  1.     #include 
  2.     void main()
  3.     {
  4.         int i = 0;
  5.         if (i == 0)
  6.         {
  7.             printf("Hello");
  8.             break;
  9.         }
  10.     }
a) Hello is printed infinite times
b) Hello
c) Varies
d) Compile time error
Answer: d
11. What is the output of this C code?

  1.     #include 
  2.     int main()
  3.     {
  4.         int i = 0;
  5.         do
  6.         {
  7.             i++;
  8.             if (i == 2)
  9.                 continue;
  10.                 printf("In while loop ");
  11.         } while (i < 2);
  12.         printf("%d\n", i);
  13.     }
a) In while loop 2
b) In while loop in while loop 3
c) In while loop 3
d) Infinite loop
Answer: a
12. What is the output of this C code?

  1.     #include 
  2.     int main()
  3.     {
  4.         int i = 0, j = 0;
  5.         for (i; i < 2; i++){
  6.             for (j = 0; j < 3; j++){
  7.                 printf("1\n");
  8.                 break;
  9.             }
  10.             printf("2\n");
  11.         }
  12.         printf("after loop\n");
  13.     }
a) 1
    2
    after loop
b) 1
    after loop
c) 1
    2
    1
    2
    after loop
d) 1
    1
    2
    after loop
Answer: c
13. What is the output of this C code?

  1.     #include 
  2.     int main()
  3.     {
  4.         int i = 0;
  5.         while (i < 2)
  6.         {
  7.             if (i == 1)
  8.                 break;
  9.                 i++;
  10.                 if (i == 1)
  11.                     continue;
  12.                     printf("In while loop\n");
  13.         }
  14.         printf("After loop\n");
  15.     }
a) In while loop
    After loop
b) After loop
c) In while loop
    In while loop
    After loop
d) In while loop
Answer: b
14. What is the output of this C code?

  1.     #include 
  2.     int main()
  3.     {
  4.         int i = 0;
  5.         char c = 'a';
  6.         while (i < 2){
  7.             i++;
  8.             switch (c) {
  9.             case 'a':
  10.                 printf("%c ", c);
  11.                 break;
  12.                 break;
  13.             }
  14.         }
  15.         printf("after loop\n");
  16.     }
a) a after loop
b) a a after loop
c) after loop
d) None of the mentioned
Answer: b
15. What is the output of this C code?

  1.     #include 
  2.     int main()
  3.     {
  4.         printf("before continue ");
  5.         continue;
  6.         printf("after continue\n");
  7.     }
a) Before continue after continue
b) Before continue
c) After continue
d) Compile time error
Answer: d

Related

Multiple Choice Questions 3776019392836739441

Post a Comment

emo-but-icon

item