ProgrammingHardProduct company OA
Assume a 64-bit LP64 ABI (8-byte long long, natural alignment). What is printed?
Assume a 64-bit LP64 ABI (8-byte long long, natural alignment). What is printed?
struct LL { char a; long long b; char c; };
printf("%zu", sizeof(struct LL));- A. 16
- B. 17
- C. 9
- D. 24
Correct answer: D. 24
a@0, 7 bytes of padding so b (8-byte aligned) sits at offset 8, ending at 16; c@16, then 7 bytes of trailing padding to round the struct up to a multiple of 8 (long long's alignment): 24 total.
More C Programming questions
- 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) {…
- What is printed? c #include <stdio.h> int isEven(int n); int isOdd(int n) { if (n == 0) return 0; return isEven(n - 1); } int isEven(int…