简体   繁体   中英

How do you calculate the size of bytes in a data structure in C, without using the sizeof() operator?

在此处输入图像描述

this question has got me so confused as to how the answer is 3. Any help is greatly appreciated!

This has nothing to do with C, arrays or pointers or sizeof. The question is about information theory -- 2 rhesus factors = 1 bit, 'A,B,AB and O' for blood types require 2 bits.

Put it another way:

There are 4 main blood groups (types of blood) – A, B, AB and O. Your blood group is determined by the genes you inherit from your parents. Each group can be either RhD positive or RhD negative, which means in total there are 8 blood groups.

log2(8) == 3

If the result would have been a fraction, say log2(7) = 2.807, the result would have been still 3 (or ceil(2.807)) for most practical purposes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM