Booleans C++ MCQ

Errorlogger
0
1. Is bool a fundamental datatype in C++?
a) Yes
b) No, it is a typedef of unsigned char
c) No, it is an enum of {false,true}
d) No, it is expanded from macros

Answer:a


2. Find the odd one out:
a) std::vector<int>
b) std::vector<short>
c) std::vector<long>
d) std::vector<bool>

Answer:d


3. What is the value of the bool?
  1. bool is_int(789.54)
a) True
b) False
c) 1
d) none of the mentioned

Answer:b


4. What happens when a null pointer is converted into bool?
a) An error is flagged
b) bool value evaluates to true
c) bool value evaluates to false
d) the statement is ignored

Answer:c


5. Which of the following statements are false?
a) bool can have two values and can be used to express logical expressions.
b) bool cannot be used as the type of the result of the function.
c) bool can be converted into integers implicitly
d) a bool value can be used in arithemetic expressions.

Answer:b


6. For what values of the expression is an if-statement block not executed?
a) 0 and all negative values
b) 0 and -1
c) 0
d) 0, all negative values, all positive values except 1

Answer:c


7. Which of the two operators ++ and — work for the bool datatype in C++?
a) None
b) ++
c) –
d) Both

Answer:b


8. What is the output of the following program?
  1.     #include <iostream>
  2.     using namespace std;
  3.     int f(int p, int q)
  4.     {
  5.         if (p > q)
  6.             return p;
  7.         else
  8.             return q;
  9.     }
  10.     main()
  11.     {
  12.         int a = 5, b = 10;
  13.         int k;
  14.         bool x = true;
  15.         bool y = f(a, b);
  16.         k =((a * b) + (x + y));
  17.         cout << k;
  18.     }
a) 55
b) 62
c) 52
d) none of the mentioned

Answer:c


9. What is the value of p?
  1.     #include <iostream>
  2.     using namespace std;
  3.     int main()
  4.     {
  5.         int p;
  6.         bool a = true;
  7.         bool b = false;
  8.         int x = 10;
  9.         int y = 5;
  10.         p = ((x | y) + (a + b));
  11.         cout << p;
  12.         return 0;
  13.     }
a) 0
b) 16
c) 12
d) 2

Answer:b


10. Evaluate the following
(false && true) || false || true
a) 0
b) 1
c) false
d) none of the mentioned

Answer:b
Tags

Post a Comment

0Comments

Post a Comment (0)

#buttons=(Accept !) #days=(30)

Our website uses cookies to enhance your experience. Check Now
Accept !