C MCQ set number 00684

1. The output of the code below is

  1.     #include <stdio.h>
  2.     void main()
  3.     {
  4.         int k = 8;
  5.         int m = 7;
  6.         k < m ? k++ : m = k;
  7.         printf("%d", k);
  8.     }

a) 7
b) 8
c) Compile time error
d) Run time error

Answer

Answer: c [Reason:] None.

2. The output of the code below is

  1.     #include <stdio.h>
  2.     void main()
  3.     {
  4.         int k = 8;
  5.         int m = 7;
  6.         k < m ? k = k + 1 : m = m + 1;
  7.         printf("%d", k);
  8.     }

a) Compile time error
b) 9
c) 8
d) Run time error

Answer

Answer: a [Reason:] None.

3. For initialization a = 2, c = 1 the value of a and c after this code will be
     c = (c) ? a = 0 : 2;
a) a = 0, c = 0;
b) a = 2, c = 2;
c) a = 2, c = 2;
d) a = 1, c = 2;

Answer

Answer: a [Reason:] None.

4. What will be the data type of the expression (a < 50) ? var1 : var2;
    provided a = int, var1 = double, var2 = float
a) int
b) float
c) double
d) Cannot be determined

Answer

Answer: c [Reason:] None.

5. Which expression has to be present in the following?
    exp1 ? exp2 : exp3;
a) exp1
b) exp2
c) exp3
d) All of the mentioned

Answer

Answer: d [Reason:] None.

6. Value of c after the following expression (initializations a = 1, b = 2, c = 1):
     c += (-c) ? a : b;
a) Syntax Error
b) c = 1
c) c = 2
d) c = 3

Answer

Answer: c [Reason:] None.

7. Comment on the following expression?
    c = (n) ? a : b; can be rewritten as
a) if (!n)c = b;
    else c = a;
b) if (n <= 0)c = b;
    else c = a;
c) if (n > 0)c = a;
    else c = b;
d) All of the mentioned

Answer

Answer: a [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.