Google News
logo
CPP - Quiz(MCQ)
What is bitset in C++?
A)
Vector of bools
B)
Template class
C)
An array of bools consuming one bit per element
D)
C-like arrays of bool elements

Correct Answer :   An array of bools consuming one bit per element


Explanation :

Bitset represents a fixed-size sequence of N bits and stores values either 0 or 1. Zero means value is false or bit is unset and one means value is true or bit is set. Bitset class emulates space efficient array of boolean values, where each element occupies only one bit.
 
As it emulates array, its index also starts from 0th position. Individual bit from bitset can be accessed using subscript operator. For instance to access first element of bitset foo use foo[0].
 
Bitset class provides constructors to create bitset from integer as well as from strings. The size of the bitset is fixed at compile time. STL provides vector<bool> class that provides dynamic resize functionality.
 
 
Below is definition of std::bitset from <bitset> header file
 
template <size_t N> class bitset;

Advertisement