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. Variables cannot be checked using a switch as in case a.
    2. Expression as in case 3 + 5 is not allowed.
    3. All cases in the switch are not unique
    4. There is no break statement in each case.
  1. View Hint | View Answer | Workspace | Discuss In Forum | Report

    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.

    Report

  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. 400 400 300
    2. Garbage 400 300
    3. 400 Garbage 300
    4. 400 400 Garbage`
  1. View Hint | View Answer | Workspace | Discuss In Forum | Report

    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

    Report

  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. Error: 'elseif is not a keyword in C'
    2. Error: 'Expression syntax'
    3. Error: 'L value required'
    4. Error: 'R value requaired'
  1. View Hint | View Answer | Workspace | Discuss In Forum | Report

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

    Correct Option: A

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

    Report

  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. Error: 'Misplaced Continue'
    2. Bye
    3. No output
    4. Good Morning
      Good Evening
  1. View Hint | View Answer | Workspace | Discuss In Forum | Report

    Continue should be used within a loop.

    Correct Option: A

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

    Report

  1. Which of the following cannot be checked in a switch - case statement?
    1. Character
    2. Integer
    3. Float
    4. enum
  1. View Hint | View Answer | Workspace | Discuss In Forum | Report

    Float

    Correct Option: C

    Float

    Report