Evaluate the following (false && true) || false || true
0
1
false
none of the mentioned
Explanation:-
Answer: Option B. -> 1
None.
Question 2.
What is the value of p?
1. #include 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. }
0
16
12
2
Explanation:-
Answer: Option B. -> 16
None.
Question 3.
What is the output of the following program?
1. #include 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
55
62
52
none of the mentioned
Explanation:-
Answer: Option C. -> 52
Question 4.
Which of the two operators ++ and - work for the bool datatype in C++?
None
++
-
Both
Explanation:-
Answer: Option B. -> ++
Due to history of using integer values as booleans, if an integer is used as a boolean, then incrementing
will mean that whatever its truth value before the operation, it will have a truth-value of true after it.
However, it’s not possible to predict the result of — given knowledge only of the truth value of x, as
it could result in false.
Question 5.
For what values of the expression is an if-statement block not executed?
0 and all negative values
0 and -1
0
0, all negative values, all positive values except 1
Explanation:-
Answer: Option C. -> 0
The if-statement block is only not executed when the expression evaluates to 0. It’s just
syntactic sugar for a branch-if-zero instruction.
Question 6.
Which of the following statements are false?
bool can have two values and can be used to express logical expressions.
bool cannot be used as the type of the result of the function.
bool can be converted into integers implicitly
a bool value can be used in arithemetic expressions.
Explanation:-
Answer: Option B. -> bool cannot be used as the type of the result of the function.
None.
Question 7.
What is the value of the bool?
1. bool is_int(789.54)
True
False
1
none of the mentioned
Explanation:-
Answer: Option B. -> False
The given number is a double not an integer, so the function returns 0 which is boolean false.
Question 8.
Is bool a fundamental datatype in C++?
Yes
No, it is a typedef of unsigned char
No, it is an enum of {false,true}
No, it is expanded from macros
Explanation:-
Answer: Option A. -> Yes
C++ has bool as a fundamental data type.
Question 9.
Find the odd one out:
std::vector
std::vector short>
std::vector
std::vector
Explanation:-
Answer: Option D. -> std::vector
std::vector<bool> is a specialized version of vector, which is used for elements of type
bool and optimizes for space. It behaves like the unspecialized version of vector and the
storage is not necessarily an array of bool values, but the library implementation may
optimize storage so that each value is stored in a single bit.
Question 10.
What happens when a null pointer is converted into bool?
An error is flagged
bool value evaluates to true
bool value evaluates to false
the statement is ignored
Explanation:-
Answer: Option C. -> bool value evaluates to false
A pointer can be implicitly converted to a bool. A nonzero pointer converts to true and zerovalued