ProgrammingHardWipro · Cognizant pattern
Assume a 64-bit LP64 ABI. What is printed?
Assume a 64-bit LP64 ABI. What is printed?
union Shape {
struct { double radius; } circle;
struct { double width, height; } rect;
};
printf("%zu", sizeof(union Shape));- A. 8
- B. 16
- C. 24
- D. 4
Correct answer: B. 16
The union's size is the size of its largest member: the anonymous rect struct, which is two doubles (width, height) with no padding needed = 16 bytes; circle is only 8 bytes, so the union is sized to fit the larger member: 16.
More C Programming questions
- Assume 32-bit int and two's complement. What is printed? c int x = 5; int y = ~x + 1; printf("%d", y);
- Assume 32-bit int. What is printed? c int x = 12; printf("%d %d %d", x & 1, x | 1, x ^ 1);
- Assume 32-bit int. What is printed? c int a = 6, b = 3; printf("%d %d %d %d", a & b, a | b, a ^ b, ~a);
- Assume 32-bit int. What is the value of n that checks whether the k-th bit (0-indexed from the LSB) of x is set, for x=44 and k=3, and…
- Assume 32-bit int. What does this snippet do, and what is printed for x=10? c int x = 10; int y = x & (x - 1); printf("%d", y);
- Assume 32-bit int. What is printed? c #define TOGGLE(flags, bit) ((flags) ^= (1 << (bit))) int flags = 0b0110; TOGGLE(flags, 1)…