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

CSE MCQs :: C-MCQs

  1. Which of the following is an invalid if-else statement?
  2. A.
    if (if (a == 1)){}
    B.
    if (func1 (a)){}
    C.
    if (a){}
    D.
    if ((char) a){}

  3. What is the output of this C code?


        int main()

        {

            int a = 1;

            if (a--)

                printf("True");

                if (a++)

                    printf("False");

        }

  4. A.
    True
    B.
    False
    C.
    True False
    D.
    No Output

  5. Comment on the output of this C code?


        int main()

        {

            int a = 1;

            if (a)

                printf("All is Well ");

                printf("I am Well\n");

            else

                printf("I am not a River\n");

        }

  6. A.
    Output will be All is Well I am Well
    B.
    Output will be I am Well I am not a River
    C.
    Output will be I am Well
    D.
    Compile time errors during compilation

  7. What is the output of this C code?


        int main()

        {

            if (printf("%d", printf(")))

                printf("We are Happy");

            else if (printf("1"))

                printf("We are Sad");

        }

  8. A.
    0We are Happy
    B.
    1We are Happy
    C.
    1We are Sad
    D.
    Compile time error

  9. What is the output of this C code(when 1 is entered)?


        void main()

        {

            double ch;

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

           scanf("%lf", &ch);

            switch (ch)

            {

            case 1:

                printf("1");

                break;

            case 2:

                printf("2");

                break;

            }

        }

  10. A.
    Compile time error
    B.
    1
    C.
    2
    D.
    Varies

  11. What is the output of this C code(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;

            }

        }

  12. A.
    1
    B.
    Compile time error
    C.
    2
    D.
    Run time error

  13. What is the output of this C code(When 1 is entered)?


        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");

            }

        }

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

  15. What is the output of this C code(When 2 is entered)?


       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");

           }

       }

  16. A.
    1
    B.
    hi 2
    C.
    Run time error
    D.
    2

  17. What is the output of this C code(When 1 is entered)?


        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;

            }

        }

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

  19. What is the output of this C code?


        int main()

        {

            int a = 1, b = 1;

            switch (a)

            {

           case a*b:

                printf("yes ");

            case a-b:

                printf("no\n");

               break;

            }

        }

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