ProgrammingHardTCS NQT · Infosys pattern
Assume a 64-bit LP64 ABI. What is printed?
Assume a 64-bit LP64 ABI. What is printed?
struct Pt { int x, y; };
struct Pt pts[4];
printf("%ld", (long)((char*)&pts[2] - (char*)&pts[0]));- A. 24
- B. 8
- C. 16
- D. 32
Correct answer: C. 16
struct Pt has no padding (two 4-byte ints, size 8). The byte distance between pts[2] and pts[0] is 2 elements * 8 bytes each = 16.
More C Programming questions
- Assume a 64-bit LP64 ABI. What is printed? c struct Vec3 { double x, y, z; }; struct Mesh { struct Vec3 verts; int count; }; printf("%zu…
- 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);