ProgrammingHardProduct-company MCQ pattern
What is printed?
What is printed?
#pragma pack(push, 1)
struct Packed { char c; int i; };
#pragma pack(pop)
printf("%zu", sizeof(struct Packed));- A. 6
- B. 8
- C. 4
- D. 5
Correct answer: D. 5
#pragma pack(1) forces 1-byte alignment for every member, eliminating padding entirely, so the struct's size is simply the sum of its members: 1 + 4 = 5 bytes.
More C Programming questions
- Assume a 64-bit LP64 ABI and 1-byte Bool. What is printed? c struct S { Bool b; double d; }; printf("%zu", sizeof(struct S));
- 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);