I am just confused about exact size of a bitset<32> element.
As the document for std::bitset::size
says:
Returns the number of bits in the bitset.
As the document of sizeof
says
Returns size in bytes of the object representation of type.
So I tried to use the two functions in the following program
#include <iostream>
using namespace std;
int main(){
unsigned char a = 0; // a = 5(00000101)
std::bitset<32> x(a);
cout << sizeof(x) << endl;
cout << x.size() << endl;
return 0;
}
The output is
8
32
Why doesn't the sizeof(x)
return 4? As 32 bits should be equal to 4 bytes, instead of 8?