Decision Making


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











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

    Hello...


  1. What will be the output of the following C code? (Assuming that we have entered the value 1 in the standard input).
    #include <stdio.h>
    void main()
    {
    char *n;
    printf("Enter a value between 1 to 3:");
    scanf("%s", n);
    switch (n)
    {
    case "1":
    printf("Hey");
    break;
    case "2":
    printf("Hello");
    break;
    }
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    Compilation Error

    error: '::main' must return 'int'
    void main()
    In function 'int main()':
    error: switch quantity not an integer
    switch (ch)