Decision Making


  1. Which of the following errors would be reported by the compiler on compiling the program given below?
    #include <studio.h>
    int main ( )
    {
    int a = 5;
    switch (n)
    {
    case 1 :
    ..
    case 2 :
    ..
    case 3 + 5 :
    ..
    case a :
    ..
    }
    return 0;
    }











  1. View Hint View Answer Discuss in Forum

    Variables cannot be checked using a switch as in case a.

    Correct Option: A

    Variables cannot be checked using a switch as in case a.


  1. Which of the following is the correct output for the program given below?
    #include <stdio.h>
    int main ()
    {
    int a = 400, b, c;
    if ( a >= 500)
    b = 400;
    c = 300;
    printf ( "%d %d %d \n" , a, b, c);
    return 0;
    }









  1. View Hint View Answer Discuss in Forum

    if( a >= 500) is equivalent to if(false).

    Correct Option: C

    if( a >= 500) is equivalent to if(false).
    So the initialization of b will never be done.
    Output
    400 Garbage 300



  1. Which of the following statement are correct about the program given below?
    #include <stdio.h>
    int main ( )
    {
    int a = 40, b = 50;
    if ( a == b )
    printf ("a is equal to b \n");
    elseif (a > b)
    printf ("a is greater than b\n");
    elseif (a < b)
    printf ("a is less than b\n");
    return 0;
    }









  1. View Hint View Answer Discuss in Forum

    To make the program work replace 'elseif' with 'else if.

    Correct Option: A

    To make the program work replace 'elseif' with 'else if.


  1. Which of the following is the correct output for the program given below ?
    #include <stdio.h>
    int main ( )
    {
    int k = 5;
    switch (k)
    {
    case 1:
    printf ("Good Morning\n");
    case 2:
    printf ("Good Evening\n");
    break;
    case 3:
    continue;
    default:
    printf ("Bye\n");
    }
    return 0;
    }









  1. View Hint View Answer Discuss in Forum

    Continue should be used within a loop.

    Correct Option: A

    Continue should be used within a loop.
    'Misplaced Continue'



  1. Which of the following cannot be checked in a switch - case statement?









  1. View Hint View Answer Discuss in Forum

    Float

    Correct Option: C

    Float