ProgrammingHardWipro · Cognizant pattern
Assume a 64-bit LP64 ABI. What is printed?
Assume a 64-bit LP64 ABI. What is printed?
struct Flags {
unsigned ready : 1;
unsigned error : 1;
unsigned mode : 2;
};
struct Flags f = {0};
f.mode = 3;
f.ready = 1;
printf("%u %u %u", f.ready, f.error, f.mode);- A. 1 0 3
- B. 0 0 3
- C. 1 1 3
- D. 1 0 0
Correct answer: A. 1 0 3
Each bit-field is an independent sub-object sharing the same underlying storage unit; setting f.mode = 3 (binary 11, fitting in its 2 bits) and f.ready = 1 only touches their own designated bits, leaving f.error untouched at its zero-initialised value. Output: 1 0 3.
More C Programming questions
- 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…
- What is printed? c #define SQUARE(x) x x int main() { int a = 5; printf("%d", SQUARE(a + 1)); }
- What is printed? c #define INCR(x) x++ int main() { int i = 5; int r = 2 INCR(i); printf("%d %d", r, i); }
- What is printed? c #define PR(x) printf(#x " = %dn", x) int main() { int value = 42; PR(value); }
- What is printed? c #define CONCAT(a, b) a##b int main() { int xy = 100; printf("%d", CONCAT(x, y)); }