Home / CSE MCQs / C-MCQs :: Control Flow Statements

CSE MCQs :: C-MCQs

  1. The output of the code below is(When 1 is entered)?


        void main()

        {

            char *ch;

            printf("enter a value btw 1 to 3:");

            scanf("%s", ch);

            switch (ch)

            {

            case "1":

                printf("1");

                break;

            case "2":

                printf("2");

                break;

            }

        }

  2. A.
    1
    B.
    2
    C.
    Compile time error
    D.
    no Compile time error

    View Answer

    Workspace

    Discuss Discuss in Forum


  3. When 1 is entered, The output of the code below is?


        void main()

        {

            int ch;

            printf("enter a value btw 1 to 2:");

            scanf("%d", &ch);

            switch (ch)

            {

            case 1:

                printf("1\n");

            default:

                printf("2\n");

            }

        }

  4. A.
    1
    B.
    2
    C.
    1 2
    D.
    Run time error

    View Answer

    Workspace

    Discuss Discuss in Forum


  5. When 2 is entered, The output of the code below is?


        void main()

        {

            int ch;

            printf("enter a value btw 1 to 2:");

            scanf("%d", &ch);

            switch (ch)

            {

            case 1:

                printf("1\n");

                break;

                printf("Hi");

            default:

                printf("2\n");

            }

        }

  6. A.
    1
    B.
    Hi 2
    C.
    Run time error
    D.
    2

    View Answer

    Workspace

    Discuss Discuss in Forum


  7. When 1 is entered, The output of the code below is?


        void main()

        {

            int ch;

            printf("enter a value btw 1 to 2:");

            scanf("%d", &ch);

            switch (ch, ch + 1)

            {

            case 1:

                printf("1\n");

                break;

            case 2:

                printf("2");

                break;

            }

        }

  8. A.
    1
    B.
    2
    C.
    3
    D.
    Run time error

    View Answer

    Workspace

    Discuss Discuss in Forum


  9. What is the output of this C code?


        int main()

        {

            int x = 1;

            if (x > 0)

                printf("inside if\n");

            else if (x > 0)

                printf("inside elseif\n");

        }

  10. A.
    inside if
    B.
    inside elseif
    C.
    inside if

         inside elseif

    D.
    Compile time error

    View Answer

    Workspace

    Discuss Discuss in Forum


  11. What is the output of this C code?


        int main()

        {

            int x = 0;

            if (x++)

                printf("true\n");

            else if (x == 1)

                printf("false\n");

        }

  12. A.
    true
    B.
    false
    C.
    Compile time error
    D.
    Undefined behaviour

    View Answer

    Workspace

    Discuss Discuss in Forum


  13. What is the output of this C code?


        int main()

        {

            int x = 0;

            if (x == 1)

                if (x == 0)

                    printf("inside if\n");

                else

                    printf("inside else if\n");

            else

                printf("inside else\n");

        }

  14. A.
    inside if
    B.
    inside else if
    C.
    inside else
    D.
    Compile time error

    View Answer

    Workspace

    Discuss Discuss in Forum


  15. What is the output of this C code?


        int main()

        {

            int x = 0;

            if (x == 0)

               printf("true, ");

            else if (x = 10)

                printf("false, ");

            printf("%d\n", x);

        }

  16. A.
    false, 0
    B.
    true, 0
    C.
    true, 10
    D.
    Compile time error

    View Answer

    Workspace

    Discuss Discuss in Forum


  17. What is the output of this C code?


        int main()

        {

            int x = 0;

            if (x == 1)

                if (x >= 0)

                    printf("true\n");

                else

                    printf("false\n");

        }

  18. A.
    true
    B.
    false
    C.
    Depends on the compiler
    D.
    No print statement

    View Answer

    Workspace

    Discuss Discuss in Forum


  19. if (a == 1||b == 2){} can be written as:
  20. A.
    if (a == 1)

         if (b == 2){}

    B.
    if (a == 1){}

         if (b == 2){}

    C.
    if (a == 1){}

         else if (b == 2){}

    D.
    None of the mentioned

    View Answer

    Workspace

    Discuss Discuss in Forum