C Loops & Control Structure

Last Updated :
Discuss
Comments

Question 1

C
#include <stdio.h>  int main() {     int i = 1024;     for (; i; i >>= 1)         printf("GeeksQuiz");     return 0; } 
How many times will GeeksQuiz be printed in the above program?
  • 10
  • 11
  • Infinite
  • The program will show compile-time error

Question 2

C
#include <stdio.h> #define PRINT(i, limit) do \\                         { \\                             if (i++ < limit) \\                             { \\                                 printf("GeeksQuiz\\n"); \\                                 continue; \\                             } \\                         }while(0);  int main() {     int i = 0;     PRINT(i, 3);     return 0; } 

How many times GeeksQuiz is printed in the above program ?
 

  • 1
     

  • 3
     

  • 4
     

  • Compile-time error
     

Question 3

What is the output of the below program? 

C
#include <stdio.h>  int main() {     int i = 2;     switch (i) {         case 0:             printf("Geeks");             break;         case 1:             printf("Quiz");             break;         default:             printf("GeeksQuiz");     }     return 0; } 
  • Geeks

  • Quiz

  • GeeksQuiz

  • Compile-time error

Question 4

C
#include <stdio.h>  int main() {     int i = 3;     switch (i) {         case 1:             printf("Geeks");             break;         case 1+2:             printf("Quiz");             break;         default:             printf("GeeksQuiz");     }     return 0; } 

What is the output of the above program?

  • Geeks

  • Quiz

  • GeeksQuiz

  • Compile-time error

Question 5

Predict the output of the below program: 

C
#include <stdio.h>  #define EVEN 0 #define ODD 1  int main() {     int i = 3;     switch (i % 2) {         case EVEN:             printf("Even");             break;         case ODD:             printf("Odd");             break;         default:             printf("Default");     }     return 0; } 
  • Even

  • Odd

  • Default

  • Compile-time error

Question 6

C
#include <stdio.h>  int main() {     int i;     if (printf("0"))         i = 3;     else         i = 5;     printf("%d", i);     return 0; } 

Predict the output of above program?

  • 3

  • 5

  • 03

  • 05

Question 7

C
#include <stdio.h>  int i;  int main() {     if (i) {         // Do nothing     } else {         printf("Else");     }     return 0; } 

What is correct about the above program?

  • if block is executed.

  • else block is executed.

  • It is unpredictable as i is not initialized.

  • Error: misplaced else

Question 8

C
#include<stdio.h> int main() {    int n;    for (n = 9; n!=0; n--)      printf("n = %d", n--);    return 0; } 
What is the output?
  • 9 7 5 3 1
  • 9 8 7 6 5 4 3 2 1
  • Infinite Loop
  • 9 7 5 3

Question 9

Output? C
#include <stdio.h> int main() {     int c = 5, no = 10;     do {         no /= c;     } while(c--);       printf ("%d\\n", no);     return 0; } 
  • 1
  • Runtime Error
  • 0
  • Compiler Error

Question 10

C
# include <stdio.h> int main() {    int i = 0;    for (i=0; i<20; i++)    {      switch(i)      {        case 0:          i += 5;        case 1:          i += 2;        case 5:          i += 5;        default:          i += 4;          break;      }      printf("%d  ", i);    }    return 0; } 
  • 5 10 15 20

  • 7 12 17 22

  • 16 21

  • Compiler Error

Tags:

There are 45 questions to complete.

Take a part in the ongoing discussion