typedef unsigned int Set[10];
Set set1;
I am correct in assuming that this creates a variable of type Set named set1 with 320 bits of storage space?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The number of bits (and bytes1) allocated may vary. Though, it is guaranteed to create a sequentiell storage for 10 integers which can be references through
set1.What does the standard say?
The standard doesn’t force a byte to contain
Nbits since that will make it harder to write compilers for a platform which doesn’t haveNbits in a byte.How would I get the number of bits in type T?
There is a constant (
CHAR_BIT) defined that holds the number of bits in a char in <climits>.Since all types consists of N bytes and a char is guaranteed to yield 1 when doing
sizeof(char)we can use this constraint to calculate the bits in any arbitrary type.The above output is, as mentioned, implementation-defined.
1 The standard doesn’t force the size of an
intto beMbytes. All it cleary states is that anintis to be able to hold at least-32767through32767(if signed), and0to65535(if unsigned).