ProgrammingHardHCL · Tech Mahindra pattern
Assume 64-bit LP64, natural alignment. What is printed?
Assume 64-bit LP64, natural alignment. What is printed?
struct S { double d; int i; };
struct S arr[3];
printf("%zu %zu", sizeof(struct S), sizeof(arr));- A. 12 36
- B. 16 48
- C. 12 48
- D. 16 36
Correct answer: B. 16 48
S: d@0 (8 bytes), i@8 (4 bytes), padded to 16 (a multiple of 8, double's alignment) so that an ARRAY of S keeps every element's double correctly aligned. sizeof(arr) = 3 * 16 = 48.
More C Programming questions
- Assume 64-bit LP64. What is printed? c struct Node { int val; struct Node next; }; printf("%zu", sizeof(struct Node));
- Assume 64-bit LP64, natural alignment, and #pragma pack(1) applied. What is printed? c #pragma pack(1) struct Packed { char c; int i; char…
- Assume 64-bit LP64, natural alignment. What is printed? c struct A { int arr[3]; char c; }; printf("%zu", sizeof(struct A));
- 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); }