ProgrammingHardTCS NQT · Infosys pattern
Assume a 64-bit LP64 ABI. What is printed?
Assume a 64-bit LP64 ABI. What is printed?
struct Bitfields {
unsigned a : 3;
unsigned b : 5;
unsigned c : 24;
};
printf("%zu", sizeof(struct Bitfields));- A. 4
- B. 3
- C. 12
- D. 8
Correct answer: A. 4
a(3)+b(5)+c(24) = 32 bits total, which fits exactly into a single 4-byte unsigned int storage unit on typical implementations (bit-field packing is implementation-defined in detail, but GCC/Clang/MSVC on common ABIs all pack these into one 4-byte unit here), giving sizeof = 4.
More C Programming questions
- Assume a 64-bit LP64 ABI. What is printed? c struct A { int x; }; struct B { struct A a; int y; }; struct B b = {{10}, 20}; struct A pa =…
- Assume a 64-bit LP64 ABI. What is printed? c struct Flags { unsigned ready : 1; unsigned error : 1; unsigned mode : 2; }; struct Flags f =…
- Assume a 64-bit LP64 ABI. What is printed? c struct Node { int value; struct Node next; }; printf("%zu", sizeof(struct Node));
- Assume a 64-bit LP64 ABI. What is printed? c typedef union { struct { unsigned char r, g, b, a; } channels; unsigned int packed; } Color…
- What is printed? c #define SQUARE(x) x x int main() { int a = 5; printf("%d", SQUARE(a + 1)); }
- What is printed? c #define INCR(x) x++ int main() { int i = 5; int r = 2 INCR(i); printf("%d %d", r, i); }