Decision Making


  1. What will be the output of the following C code?
    #include <stdio.h>
    int main()
    {
    float n = 12;
    switch (n)
    {
    case 1.0:
    printf("Option: First\n");
    break;
    default:
    printf("Option: Default\n");
    }
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

    Compilation Error

    In function 'int main()':
    error: switch quantity not an integer
    switch (n)


  1. What will be the output of the following C code?
    #include <stdio.h>
    int main()
    {
    int n = 98;
    switch (n)
    {
    case 'b':
    printf("Right... ");
    break;
    case 98:
    printf("Wrong...\n");
    break;
    }
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

    Compilation Error

    In function 'int main()':
    error: duplicate case value
    case 98:
    error: previously used here
    case 'b':



  1. What will be the output of the following C code?
    #include <stdio.h>
    int main()
    {
    int n = 10, m = 10;
    switch (n)
    {
    case n*m:
    printf("True ");
    case n-m:
    printf("False\n");
    break;
    }
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: B

    Compilation Error

    In function 'int main()':
    error: 'n' cannot appear in a constant-expression
    case n-m:
    error: 'm' cannot appear in a constant-expression
    case n*m:
    error: 'n' cannot appear in a constant-expression
    case n-m:
    error: 'm' cannot appear in a constant-expression
    case n-m:


  1. What will be the output of the following C code? (Assuming that we have entered the value 2 in the standard input).
    #include <stdio.h>
    int main()
    {
    int var;
    printf("Enter a value between 1 to 2: ");
    scanf("%d", &var);
    switch (var, var + 1)
    {
    case 1:
    printf("Option 1.");
    break;
    case 2:
    printf("Option 2.");
    break;
    default :
    printf("Default option.");
    }
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    Default option.



  1. What will be the output of the following C code? (Assuming that we have entered the value 2 in the standard input).
    #include <stdio.h>
    int main()
    {
    int p;
    printf("Enter a value between 1 to 2:");
    scanf("%d", &p);
    switch (p)
    {
    case 1:
    printf("hey...\n");
    break;
    printf("Hello...");
    default:
    printf("How are U?\n");
    }
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    How are U?