ProgrammingHardHCL · Tech Mahindra pattern

Assume a 64-bit LP64 ABI. What is printed?

Assume a 64-bit LP64 ABI. What is printed?
struct Rect {
    struct { int x, y; } topLeft;
    struct { int x, y; } bottomRight;
};
struct Rect r = {{0, 0}, {10, 20}};
int width = r.bottomRight.x - r.topLeft.x;
int height = r.bottomRight.y - r.topLeft.y;
printf("%d %d", width, height);
  1. A. 10 20
  2. B. 0 0
  3. C. 20 10
  4. D. 10 10

Correct answer: A. 10 20

topLeft is (0,0) and bottomRight is (10,20) via the nested anonymous-struct-type members; width = 10-0=10, height = 20-0=20.

More C Programming questions

Exams that ask this topic