Quiz


  1. The execution of a loop typically starts with:
  2. initialization statements
    Loop body
    test condition
    update statements

  3. The break statement is used to exit from:
  4. an if statement
    a for loop
    a program
    the main( ) function

  5. A do-while loop is useful when we want that the statements within the loop must be executed
  6. Only once
    At Least Once
    More than once
    None of the above

  7. In what sequence the initialization, testing and execution of body is done in a do-while loop
  8. Initialization, execution of body, testing
    Execution of body, initialization, testing
    Initialization, testing, execution of body
    None of the above

  9. Which of the following is not an infinite loop.
  10. int i = 1 ;             
    while ( 1 ) 
    { 
        i++ ; 
    }

    for( int i =1; i< 10; i--)
    printf("Hello World");
        

    for(int i =1; i<100; i++)
    printf("Hello World");
        
    int i = 0; 
    do{
    i--
    printf("%d ",i);
    }while(i>0);
        

  11. Which of the following statement is used to take the control to the beginning of the loop?
  12. exit
    break
    continue
    None of the above

  13. How many * this code will print:
  14. 
    main()
    {
       int i;
        for (i=1;i<3;i++)
          printf("*");
    }
        
    0
    1
    2
    3

  15. Multiple intialization is not possible in for loop
  16. True
    False

  17. For loop can be converted into equivalent while loop
  18. True
    False

  19. Loop can not be nested
  20. True
    False

  21. When break is encountered inside any loop, control automatically passes to the beginning of the loop.
  22. True
    False

  23. Which of the following is not a loop in C
  24. Repeat
    Do while
    While
    For

  25. What is the output of the following code:
  26. 
    main( ) 
    { 
       int j =2; 
       while ( j <= 1) 
       { 
             printf ( "%d ", j ) ; 
             j=j+1; 
       } 
    } 
        
    Syntax Error
    1 2
    1 2 3
    Print nothing

  27. What is the output of the following code:
  28. 
    main( ) 
    { 
       int x = 1 ; 
       while ( x == 1 ) 
       { 
            x=x-1; 
            printf ( "\n%d", x ) ; 
       } 
    } 
        
    0
    1
    2
    3

  29. What is the output of the following code:
  30. 
    main( ) 
    { 
       while ( 'a' < 'b' ) 
            printf ( "hello world" ) ; 
    }
    
        
    Hello world
    Syntax error
    Print nothing
    Run Time error

  31. What is the output of the following code:
  32. 
    main()
    {
     int i = 0;
       do
           {
                 printf("Hello");
                 i++;
           }
       while(i > 1);
    }
        
    Syntax Error
    Hello
    HelloHello
    Infinite Loop

  33. What is the output of the following code:
  34. 
    main()
    {
     int i = 0;
       do
           {
                 printf("%d", i);
                 i++;
           }
       while(i < 2);
    } 
        
    1
    2
    1 2
    1 2 3

  35. How many * this code will print:
  36. 
    main()
    {
    int i,j
    for (i =1; i<=5;i++)
         for(j=i;j<=5;j++)
               printf("*");
    }
        
    25
    20
    15
    10

  37. Which of the following is an exit controlled loop:
  38. For
    While
    Do-While
    None of the above

  39. Which among the following is an unconditional control structure:
  40. goto
    break
    continue
    if else