ProgrammingHardHCL · Tech Mahindra pattern
Assume 64-bit LP64, natural alignment. What is printed?
Assume 64-bit LP64, natural alignment. What is printed?
struct A { int arr[3]; char c; };
printf("%zu", sizeof(struct A));- A. 16
- B. 13
- C. 12
- D. 15
Correct answer: A. 16
arr occupies 12 bytes (3 ints), already aligned; c follows at offset 12 (1 byte), making the raw total 13. The struct must then be padded to a multiple of 4 (int's alignment, the strictest member), rounding up to 16.
More C Programming questions
- What is printed? c int f(int n) { if (n <= 1) return 1; return n f(n - 1); } int main() { printf("%d", f(5)); }
- What is printed? c int f(int n) { if (n == 0) return 0; int x = f(n - 1); printf("%d ", n); return x + n; } int main() { printf("= %d"…
- What is printed? c int depth = 0; void f(int n) { depth++; if (n == 0) return; f(n - 1); } int main() { f(3); printf("%d", depth); }
- What is printed? c void f(int n) { if (n <= 0) return; printf("%d ", n); if (n % 2 == 0) f(n / 2); else f(n - 1); } int main() { f(6); }
- Assume a 64-bit LP64 ABI. What is printed? c int x = 5, y = 10, z = 15; int arr[3] = {&x, &y, &z}; int p = arr; printf("%d %d %d", arr[1]…
- Assume a 64-bit LP64 ABI. Which declaration makes p an array of 5 pointers to int, and which makes q a pointer to an array of 5 ints?