ProgrammingVery hardHCL · Tech Mahindra pattern
Assume enum's underlying type is int (typical on common compilers) and a 64-bit LP64 ABI. What is printed?
Assume enum's underlying type is int (typical on common compilers) and a 64-bit LP64 ABI. What is printed?
enum Color { RED, GREEN, BLUE };
struct S { enum Color c; char tag; };
printf("%zu", sizeof(struct S));- A. 8
- B. 5
- C. 4
- D. 12
Correct answer: A. 8
c is stored as a 4-byte int-sized enum at offset 0; tag@4 (1 byte); end 5 is padded up to the struct's alignment, 4 (from the enum/int), giving 8.
More C Programming questions
- 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));
- Assume 32-bit int, two's complement. What is printed? c int x = ~0; printf("%d %u", x, (unsigned int)x);