Machine-translated by Google. Questions are authored in English.
Top

Discussion

What is the output of this program?

void main()
  {
  struct bitfields {
  int bits_1: 2;
  int bits_2: 9;
  int bits_3: 6;
  int bits_4: 1;
  }bit;
  printf("%d", sizeof(bit));
}

 

  • A.2
  • B.3
  • C.4

Answer: B

Correct answer: 3

The bit-fields total \(2 + 9 + 6 + 1 = 18\) bits. Rounded up to whole bytes that is 3 under the packing this question assumes. (In practice most compilers align bit-fields to their underlying type and would report 4, which is why bit-field layout is implementation-defined and not portable.)

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.