Sail E0 Webinar

MCQs

Total Questions : 97 | Page 5 of 10 pages
Question 41. 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");

       }

   }

  1.    1
  2.    hi 2
  3.    Run time error
  4.    2
 Discuss Question
Answer: Option D. -> 2


none


Question 42. 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");

        }

    }

  1.    yes
  2.    yes default
  3.    Undefined behaviour
  4.    Compile time error
 Discuss Question
Answer: Option D. -> Compile time error


none


Question 43. 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;

        }

    }

  1.    1
  2.    2
  3.    3
  4.    Run time error
 Discuss Question
Answer: Option B. -> 2


none


Question 44. 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;

        }

    }

  1.    yes
  2.    yes no
  3.    Duplicate case value error
  4.    Character case value error
 Discuss Question
Answer: Option C. -> Duplicate case value error


none


Question 45. 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;

        }

    }

  1.    yes
  2.    no
  3.    Compile time error
  4.    yes no
 Discuss Question
Answer: Option C. -> Compile time error


none


Question 46. 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;

        }

    }

  1.    yes no
  2.    yes
  3.    no
  4.    Compile time error
 Discuss Question
Answer: Option D. -> Compile time error


none


Question 47. 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;

        }

    }

  1.    yes no
  2.    yes
  3.    no
  4.    Compile time error
 Discuss Question
Answer: Option C. -> no


none


Question 48. 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;

        }

    }

  1.    Do
  2.    DoFirst
  3.    DoSecond
  4.    DoDefault
 Discuss Question
Answer: Option C. -> DoSecond


none


Question 49. Switch statement accepts.
  1.    int
  2.    char
  3.    long
  4.    All of the mentioned
 Discuss Question
Answer: Option D. -> All of the mentioned


none


Question 50. 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);

    }

  1.    No error, output is 1111
  2.    No error, output is 1
  3.    Compile time error, no break statements
  4.    Compile time error, case label outside switch statement
 Discuss Question
Answer: Option D. -> Compile time error, case label outside switch statement


none


Latest Videos

Latest Test Papers