ProgrammingHardWipro · Cognizant pattern
Assume a 64-bit LP64 ABI. What is printed?
Assume a 64-bit LP64 ABI. What is printed?
struct Vec3 { double x, y, z; };
struct Mesh { struct Vec3 *verts; int count; };
printf("%zu %zu", sizeof(struct Vec3), sizeof(struct Mesh));- A. 24 12
- B. 24 16
- C. 24 20
- D. 20 16
Correct answer: B. 24 16
Vec3 is three doubles, no padding needed: 24 bytes. Mesh: verts (pointer, 8 bytes)@0, count (int, 4 bytes)@8, end 12, padded up to 16 because the struct's alignment is 8 (driven by the pointer member).
More C Programming questions
- What is printed? c unsigned char x = 0xF0; printf("%d", (x ^ 0xFF) & 0x0F);
- What is printed? c int flags = 0; flags |= (1 << 2); flags |= (1 << 4); flags &= ~(1 << 2); printf("%d", flags);
- What is printed? c unsigned int x = 10; printf("%d", (x << 1) == (x 2)); printf(" %d", (x >> 1) == (x / 2));
- Assume 32-bit int, two's complement. What is printed? c int x = ~0; printf("%d %u", x, (unsigned int)x);
- Assume 32-bit int. What is printed? c int x = 13; int count = 0; while (x) { count += x & 1; x >>= 1; } printf("%d", count);
- Assume 32-bit int. What is printed? c int x = -5; printf("%d", x & 1);