ProgrammingHardWipro · Cognizant pattern
Assume unsigned int bitfields pack into 32-bit units and a 64-bit LP64 ABI. What is printed?
Assume unsigned int bitfields pack into 32-bit units and a 64-bit LP64 ABI. What is printed?
struct N { unsigned a:20; int b; };
printf("%zu", sizeof(struct N));- A. 4
- B. 12
- C. 8
- D. 5
Correct answer: C. 8
a reserves a full 4-byte allocation unit even though only 20 of its 32 bits are used; the remaining 12 bits cannot be shared with a plain (non-bitfield) int. b is placed right after at offset 4, giving a total of 8 bytes.
More C Programming questions
- Assume a 64-bit LP64 ABI (8-byte long long, natural alignment). What is printed? c struct LL { char a; long long b; char c; }…
- Assume a 64-bit LP64 ABI. What is printed? c union Val { int i; float f; }; union Val arr[4]; printf("%zu %zu", sizeof(union Val)…
- Assume a 64-bit LP64 ABI. What is printed? c struct K { const int a; int b; }; printf("%zu", sizeof(struct K));
- What is printed? c #include <stdio.h> int f(int n) { static int sum = 0; sum += n; if (n == 0) return sum; return f(n - 1); } int…
- What is printed? c #include <stdio.h> void f(int n) { if (n == 0) return; printf("%d ", n); f(n - 1); printf("%d ", n); } int main(void) {…
- What is printed? c #include <stdio.h> void rev(const char s) { if (s == '0') return; rev(s + 1); putchar(s); } int main(void) {…