C++ MCQs - BitSet
This section focuses on the "BitSet" in C++ programming langauge. These Multiple Choice Questions (MCQ) should be practiced to improve the C++ programming skills required for various interviews (campus interview, walk-in interview, company interview), placement, entrance exam and other competitive examinations.
1. Space taken by bitset bs is less than?
A. bool bs[N]
B. vector bs(N)
C. Both A and B
D. None of the above
View Answer
Ans : C
Explanation: space taken by bitset bs is less than that of bool bs[N] and vector bs(N)
2. What is true about bitset?
A. A bitset is an array of bool
B. A limitation of bitset is, N must be known at compile time
C. As bitset stores the same information in compressed manner the operation on bitset are faster than that of array and vector.
D. All of the above
View Answer
Ans : D
Explanation: All of the above statement is true.
3. The size of bitset is fixed at compile time that is, it can’t be changed at runtime.
A. TRUE
B. FALSE
C. Can be true and false
D. Can not say
View Answer
Ans : A
Explanation: Yes, The size of bitset is fixed at compile time that is, it can’t be changed at runtime.
4. Which bitset method tests whether all bits from bitset are set or not?
A. bitset::any()
B. bitset::test()
C. bitset::all()
D. bitset::operator[]
View Answer
Ans : C
Explanation: bitset::all() : Tests whether all bits from bitset are set or not.
5. Which bitset method toggles all bits from bitset?
A. bitset::count()
B. bitset::flip()
C. bitset::test()
D. bitset::to_ullong()
View Answer
Ans : B
Explanation: bitset::flip() : Toggles all bits from bitset.
6. bitset::hash() used for?
A. Convert hash value to unsigned long
B. Returns hash value based on the provided bitset.
C. Reports the size of the hash.
D. Reset hash value to zero.
View Answer
Ans : B
Explanation: bitset::hash() : Returns hash value based on the provided bitset.
7. Which of the following is the limitation of bitset over vector bool?
A. Space
B. Size
C. Type
D. Speed
View Answer
Ans : B
Explanation: Bitset size is static whereas vector size is dynamic therefore the size of a vector can be increased or decreased which is not possible in bitset.
8. Which operator is used to access the nth bit in a bitset?
A. $
B. #
C. []
D. *
View Answer
Ans : C
Explanation: [] operator is used to access the nth bit of a bitset from the right side. For example, if my bitset b is 1010 then b[0] represents 0 and b[1] represents 1.
9. How many ways are there for constructing a bitset?
A. 1
B. 2
C. 3
D. 4
View Answer
Ans : C
Explanation: There are three ways of constructing a bitset. Direct construction, using integer number and using binary string.
10. What is the default value of a bitset?
A. 0
B. 1
C. -1
D. infinite
View Answer
Ans : A
Explanation: By default, all the bits of a bitset variable is set to 0 i.e. the value of bitset variable is 0.
Discussion