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
2. Find the odd one out:
a) std::vector<int>
b) std::vector<short>
c) std::vector<long>
d) std::vector<bool>
3. What is the value of the bool?
a) True
b) False
c) 1
d) none of the mentioned
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
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.
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
7. Which of the two operators ++ and — work for the bool datatype in C++?
a) None
b) ++
c) –
d) Both
8. What is the output of the following program?
a) 55
b) 62
c) 52
d) none of the mentioned
9. What is the value of p?
a) 0
b) 16
c) 12
d) 2
10. Evaluate the following
(false && true) || false || true
a) 0
b) 1
c) false
d) none of the mentioned
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?
bool is_int(789.54)
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?
#include <iostream>
using namespace std;
int f(int p, int q)
{
if (p > q)
return p;
else
return q;
}
main()
{
int a = 5, b = 10;
int k;
bool x = true;
bool y = f(a, b);
k =((a * b) + (x + y));
cout << k;
}
b) 62
c) 52
d) none of the mentioned
Answer:c
9. What is the value of p?
#include <iostream>
using namespace std;
int main()
{
int p;
bool a = true;
bool b = false;
int x = 10;
int y = 5;
p = ((x | y) + (a + b));
cout << p;
return 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