Test Series - cpp

Test Number 78/102

Q: What is bitset in C++?
A. An array of bools consuming one bit per element
B. Vector of bools
C. C-like arrays of bool elements
D. Template class
Solution: Bitset is a collection of bool variables with each element consuming only one bit. They are introduced for efficient use of memories.
Q: Which of the following is correct about bitset and vector of bools?
A. Space consumed by bitset is less than vector
B. Bitset consume only 1 bit per element
C. Number of elements in bitset should be known at compile time whereas vector can have a dynamic size
D. All of the mentioned
Solution: Bitset consumes less space compared to bool vector however the size for bitset is static whereas for bool vector size is dynamic.
Q: Which of the following is the limitation of bitset over vector bool?
A. Space
B. Size
C. Type
D. Speed
Solution: 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.
Q: Which operator is used to access the nth bit in a bitset?
A. ->
B. []
C. .
D. *
Solution: [] 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.
Q: How many ways are there for constructing a bitset?
A. 1
B. 2
C. 3
D. 4
Solution: There are three ways of constructing a bitset. Direct construction, using integer number and using binary string.
Q: Which is the correct syntax of constructing a bitset?
A. bitset b;
B. bitset b(12);
C. bitset b(string(“1100”));
D. all of the mentioned
Solution: All of the above mentioned are correct syntax of constructing a bitset. However each has different way of interpretation.
Q: Which of the following is corect way of constructing bitset using integer number?
A. bitset b;
B. bitset b(12);
C. bitset b(string(“1100”));
D. bitset b(float(12));
Solution: The correct way of constructing bitset using integer number is as follows:
bitset b(integer_number);
Q: Which of the following is corect way of constructing bitset using binary string?
A. bitset b;
B. bitset b(12);
C. bitset b(string(“1100”));
D. bitset b(float(12));
Solution: The correct way of constructing bitset using binary string is as follows:
bitset b(string(“1100”));
Q: What is the default value of a bitset?
A. All bits are 0
B. All bits are 1
C. Leftmost bit is 0
D. Rightmost bit is 0
Solution: By default, all the bits of a bitset variable is set to 0 i.e. the value of bitset variable is 0.
Q: Which header file is required for using bitset in your program?
A. 
B. 
C. 
D. 
Solution:  header file is required to use the functionality of bitsets in your program i.e. use of binary string in your program.

You Have Score    /10