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

CSE MCQs :: C-MCQs

  1. What is the output of this C code?


       int main()

        {

            int x = 97;

            switch (x)

            {

            case 'a':

                printf("yes ");

                break;

            case 97:

                printf("no\n");

                break;

            }

        }

  2. A.
    yes
    B.
    yes no
    C.
    Duplicate case value error
    D.
    Character case value error

    View Answer

    Workspace

    Discuss Discuss in Forum


  3. What is the output of this C code?


        int main()

        {

            float f = 1;

            switch (f)

            {

            case 1.0:

                printf("yes\n");

                break;

            default:

                printf("default\n");

            }

        }

  4. A.
    yes
    B.
    yes default
    C.
    Undefined behaviour
    D.
    Compile time error

    View Answer

    Workspace

    Discuss Discuss in Forum


  5. What is the output of this C code?


        const int a = 1,  b = 2;

        int main()

        {

            int x = 1;

            switch (x)

            {

            case a:

                printf("yes ");

            case b:

                printf("no\n");

                break;

            }

        }

  6. A.
    yes no
    B.
    yes
    C.
    no
    D.
    Compile time error

    View Answer

    Workspace

    Discuss Discuss in Forum


  7. What is the output of this C code?


        #define max(a) a

        int main()

        {

           int x = 1;

            switch (x)

           {

            case max(2):

                printf("yes\n");

            case max(1):

                printf("no\n");

                break;

            }

        }

  8. A.
    yes no
    B.
    yes
    C.
    no
    D.
    Compile time error

    View Answer

    Workspace

    Discuss Discuss in Forum


  9. What is the output of this C code?


        int main()

        {

            switch (printf("Do"))

            {

            case 1:

                printf("First\n");

                break;

            case 2:

                printf("Second\n");

                break;

            default:

                printf("Default\n");

                break;

            }

        }

  10. A.
    Do
    B.
    DoFirst
    C.
    DoSecond
    D.
    DoDefault

    View Answer

    Workspace

    Discuss Discuss in Forum


  11. Comment on the output of this C code?


        int main()

        {

            int a = 1;

            switch (a)

            case 1:

               printf("%d", a);

            case 2:

                printf("%d", a);

            case 3:

               printf("%d", a);

           default:

                printf("%d", a);

        }

  12. A.
    No error, output is 1111
    B.
    No error, output is 1
    C.
    Compile time error, no break statements
    D.
    Compile time error, case label outside switch statement

    View Answer

    Workspace

    Discuss Discuss in Forum


  13. Switch statement accepts.
  14. A.
    int
    B.
    char
    C.
    long
    D.
    All of the mentioned

    View Answer

    Workspace

    Discuss Discuss in Forum


  15. Comment on the output of this C code?


        int main()

        {

            int a = 1;

           switch (a)

            {

           case a:

                printf("Case A ");

            default:

                printf("Default");

            }

        }

  16. A.
    Output: Case A
    B.
    Output: Default
    C.
    Output: Case A Default
    D.
    Compile time error

    View Answer

    Workspace

    Discuss Discuss in Forum


  17. What is the output of this C code?


        int main()

        {

           while ()

                printf("In while loop ");

            printf("After loop\n");

        }

  18. A.
    In while loop after loop
    B.
    After loop
    C.
    Compile time error
    D.
    Infinite loop

    View Answer

    Workspace

    Discuss Discuss in Forum


  19. What is the output of this C code?


        int main()

        {

           do

               printf("In while loop ");

           while (0);

               printf("After loop\n");

       }

  20. A.
    In while loop
    B.
    In while loop after loop
    C.
    After loop
    D.
    Infinite loop

    View Answer

    Workspace

    Discuss Discuss in Forum