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);- A. 10 20
- B. 0 0
- C. 20 10
- 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
- Assume a 64-bit LP64 ABI. What is printed? c typedef struct { int code; char message[20]; } Error; Error makeError(int c, const char msg)…
- Assume a 64-bit LP64 ABI. What is printed? c struct Counter { int value; }; void increment(struct Counter c) { c->value++; } int…
- Assume a 64-bit LP64 ABI. What is printed? c struct Pair { int a, b; }; struct Pair swapPair(struct Pair p) { int tmp = p.a; p.a = p.b…
- Assume a 64-bit LP64 ABI. What is printed? c struct Employee { char name[20]; int id; float salary; }; struct Employee e1 = {"Alice", 101…
- Assume a 64-bit LP64 ABI. What is printed? c struct Point { int x, y; }; struct Point make(int a, int b) { struct Point p = {a, b}; return…
- Assume a 64-bit LP64 ABI. What is printed? c typedef struct { int x; int y; } Point; Point p1 = {1, 2}; Point p2 = {1, 2}; printf("%d"…