ProgrammingHardTCS NQT · Infosys pattern
Assume a 64-bit LP64 ABI. What is printed?
Assume a 64-bit LP64 ABI. What is printed?
struct S { double d; char c; };
struct S arr[2];
printf("%zu %ld", sizeof(arr), (char *)&arr[1] - (char *)&arr[0]);- A. 32 16
- B. 18 9
- C. 32 9
- D. 18 16
Correct answer: A. 32 16
struct S: d@0 (8), c@8 (1), then 7 trailing padding bytes so the struct size (16) is a multiple of 8 (double's alignment). An array of 2 such structs is 32 bytes, and consecutive elements are exactly sizeof(struct S) = 16 bytes apart.
More C Programming questions
- Assume a 64-bit LP64 ABI. What is printed? c union Shape { struct { double radius; } circle; struct { double width, height; } rect; }…
- Assume 32-bit int and two's complement. What is printed? c int x = 5; int y = ~x + 1; printf("%d", y);
- Assume 32-bit int. What is printed? c int x = 12; printf("%d %d %d", x & 1, x | 1, x ^ 1);
- Assume 32-bit int. What is printed? c int a = 6, b = 3; printf("%d %d %d %d", a & b, a | b, a ^ b, ~a);
- Assume 32-bit int. What is the value of n that checks whether the k-th bit (0-indexed from the LSB) of x is set, for x=44 and k=3, and…
- Assume 32-bit int. What does this snippet do, and what is printed for x=10? c int x = 10; int y = x & (x - 1); printf("%d", y);