ProgrammingHardWipro · Cognizant pattern
Assume a 64-bit LP64 ABI and 1-byte Bool. What is printed?
Assume a 64-bit LP64 ABI and 1-byte _Bool. What is printed?
struct S { _Bool b; double d; };
printf("%zu", sizeof(struct S));- A. 9
- B. 16
- C. 12
- D. 8
Correct answer: B. 16
b@0 (1 byte); d needs 8-byte alignment so it is pushed to offset 8 (7 padding bytes), occupying 8-15; end 16 is already a multiple of 8.
More C Programming questions
- Assume enum's underlying type is int (typical on common compilers) and a 64-bit LP64 ABI. What is printed? c enum Color { RED, GREEN, BLUE…
- Assume a 64-bit LP64 ABI. What is printed? c struct Pt { int x, y; }; struct Pt pts[4]; printf("%ld", (long)((char)&pts[2]…
- 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));