ProgrammingHardHCL · Tech Mahindra pattern
Assume a 64-bit LP64 ABI. What is printed?
Assume a 64-bit LP64 ABI. What is printed?
union Data {
int i;
float f;
};
union Data d;
d.i = 1065353216;
printf("%.1f", d.f);- A. 1065353216.0
- B. 1.0
- C. 0.0
- D. Undefined behaviour: reading f after writing i
Correct answer: B. 1.0
1065353216 is exactly the IEEE-754 single-precision bit pattern for 1.0f. Reading d.f after writing d.i reinterprets those same bits as a float (type punning through a union, which most C compilers, and C11's own wording, treat as well-defined), giving 1.0.
More C Programming questions
- Assume a 64-bit LP64 ABI. What is printed? c struct Bitfields { unsigned a : 3; unsigned b : 5; unsigned c : 24; }; printf("%zu"…
- Assume a 64-bit LP64 ABI. What is printed? c struct A { int x; }; struct B { struct A a; int y; }; struct B b = {{10}, 20}; struct A pa =…
- Assume a 64-bit LP64 ABI. What is printed? c struct Flags { unsigned ready : 1; unsigned error : 1; unsigned mode : 2; }; struct Flags f =…
- 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)); }