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]));
  1. A. 24
  2. B. 8
  3. C. 16
  4. 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

Exams that ask this topic