C MCQ set number 00686

1. What is the output of this C code?

  1.     #include <stdio.h>
  2.     const int a = 1,  b = 2;
  3.     int main()
  4.     {
  5.         int x = 1;
  6.         switch (x)
  7.         {
  8.         case a:
  9.             printf("yes ");
  10.         case b:
  11.             printf("non");
  12.             break;
  13.         }
  14.     }

a) yes no
b) yes
c) no
d) Compile time error

Answer

Answer: d [Reason:] None.

2. What is the output of this C code?

  1.     #include <stdio.h>
  2.     #define max(a) a
  3.     int main()
  4.     {
  5.         int x = 1;
  6.         switch (x)
  7.         {
  8.         case max(2):
  9.             printf("yesn");
  10.         case max(1):
  11.             printf("non");
  12.             break;
  13.         }
  14.     }

a) yes no
b) yes
c) no
d) Compile time error

Answer

Answer: c [Reason:] None.

3. What is the output of this C code?

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         switch (printf("Do"))
  5.         {
  6.         case 1:
  7.             printf("Firstn");
  8.             break;
  9.         case 2:
  10.             printf("Secondn");
  11.             break;
  12.         default:
  13.             printf("Defaultn");
  14.             break;
  15.         }
  16.     }

a) Do
b) DoFirst
c) DoSecond
d) DoDefault

Answer

Answer: c [Reason:] None.

4. Comment on the output of this C code?

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         int a = 1;
  5.         switch (a)
  6.         case 1:
  7.             printf("%d", a);
  8.         case 2:
  9.             printf("%d", a);
  10.         case 3:
  11.             printf("%d", a);
  12.         default:
  13.             printf("%d", a);
  14.     }

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

Answer

Answer: d [Reason:] None.

5. Switch statement accepts.
a) int
b) char
c) long
d) all of the mentioned

Answer

Answer: d [Reason:] None.

6. Comment on the output of this C code?

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         int a = 1;
  5.         switch (a)
  6.         {
  7.         case a:
  8.             printf("Case A ");
  9.         default:
  10.             printf("Default");
  11.         }
  12.     }

a) Output: Case A
b) Output: Default
c) Output: Case A Default
d) Compile time error

Answer

Answer: d [Reason:] None.

7. Comment on the output of this C code?

  1.     #include <stdio.h>
  2.     switch (ch)
  3.     {
  4.     case 'a':
  5.     case 'A':
  6.         printf("true");
  7.     }

a) if (ch == ‘a’ && ch == ‘A’) printf(“true”);
b) if (ch == ‘a’)
    if (ch == ‘a’) printf(“true”);
c) if (ch == ‘a’ || ch == ‘A’) printf(“true”);
d) none of the mentioned

Answer

Answer: c [Reason:] None.

ed010d383e1f191bdb025d5985cc03fc?s=120&d=mm&r=g

DistPub Team

Distance Publisher (DistPub.com) provide project writing help from year 2007 and provide writing and editing help to hundreds student every year.