ProgrammingHardWipro · Cognizant pattern
Assume a 64-bit LP64 ABI. What is printed?
Assume a 64-bit LP64 ABI. What is printed?
struct Point { int x; int y; };
struct Rect { struct Point tl; struct Point br; };
printf("%zu %zu", sizeof(struct Point), sizeof(struct Rect));- A. 8 16
- B. 4 8
- C. 8 8
- D. 8 12
Correct answer: A. 8 16
Point has two 4-byte ints with no padding needed between them (both naturally aligned at offsets 0 and 4), so sizeof(Point)=8. Rect embeds two Points back-to-back (each already a clean multiple of int's alignment), so sizeof(Rect)=16 with no extra padding.
More C Programming questions
- Assume a 64-bit LP64 ABI. What is printed? c union Data { int i; float f; }; union Data d; d.i = 1065353216; printf("%.1f", d.f);
- Assume a 64-bit LP64 ABI. What is printed? c struct Bitfields { unsigned a : 3; unsigned b : 5; unsigned c : 24; }; printf("%zu"…
- Assume a 64-bit LP64 ABI. What is printed? c struct A { int x; }; struct B { struct A a; int y; }; struct B b = {{10}, 20}; struct A pa =…
- Assume a 64-bit LP64 ABI. What is printed? c struct Flags { unsigned ready : 1; unsigned error : 1; unsigned mode : 2; }; struct Flags f =…
- Assume a 64-bit LP64 ABI. What is printed? c struct Node { int value; struct Node next; }; printf("%zu", sizeof(struct Node));
- Assume a 64-bit LP64 ABI. What is printed? c typedef union { struct { unsigned char r, g, b, a; } channels; unsigned int packed; } Color…