ProgrammingVery hardProduct company OA
Assume unsigned int bitfields pack into 32-bit allocation units and a zero-width bitfield forces the next field to a new unit. What is printed?
Assume unsigned int bitfields pack into 32-bit allocation units and a zero-width bitfield forces the next field to a new unit. What is printed?
struct ZW { unsigned a:3; unsigned :0; unsigned b:5; };
printf("%zu", sizeof(struct ZW));- A. 4
- B. 1
- C. 5
- D. 8
Correct answer: D. 8
The unnamed :0 bitfield forces the next bitfield (b) to begin at the start of a new allocation unit, even though 29 bits were still free after a. So a occupies one 4-byte unit and b starts a second 4-byte unit: 8 bytes total.
More C Programming questions
- On a little-endian 64-bit machine, what is printed? c union U { int i; char c[4]; }; union U u; u.i = 0x41424344; printf("%c%c%c%c"…
- Assume a 64-bit LP64 ABI. What is printed? c struct Variant { int type; union { int i; float f; double d; }; }; printf("%zu"…
- Assume a 64-bit LP64 ABI. What is printed? c struct Node { char tag; struct Node next; int val; }; printf("%zu", sizeof(struct Node));
- Assume unsigned int bitfields pack into 32-bit units and a 64-bit LP64 ABI. What is printed? c #include <stddef.h> struct M { unsigned…
- Assume a 64-bit LP64 ABI. What is printed? c struct A { char a; double d; char b; }; struct B { double d; char a; char b; }; printf("%zu…
- On a little-endian 64-bit machine, what is printed? c union U { int i; struct { short lo; short hi; } s; }; union U u; u.i = 0x00020001…