ProgrammingVery hardProduct company OA · GATE CS
Assume IEEE-754 single-precision float and 32-bit unsigned int. What is printed?
Assume IEEE-754 single-precision float and 32-bit unsigned int. What is printed?
union { float f; unsigned u; } v = {1.0f};
printf("%08X", v.u);- A. 7F800000
- B. 40000000
- C. 00000001
- D. 3F800000
Correct answer: D. 3F800000
1.0 is sign 0, exponent 127 (the bias) and fraction 0: 0 01111111 000…0, which is 0x3F800000. 0x40000000 is 2.0 and 0x7F800000 is infinity. Reading another union member reinterprets the bytes; it does not convert 1.0 to the integer 1.
More C Programming questions
- What is printed? c #line 100 int a = LINE; int b = LINE; printf("%d %d", a, b);
- What is printed? c #define CAT(a, b) a##b printf("%d", CAT(1, 2) + CAT(0x, 1F));
- What is printed? c #define f(x) ((x) 2) int (f)(int x) { return x + 100; } int main(void) { printf("%d %d", f(1), (f)(1)); }
- What is printed? c if (strcmp("abc", "abc")) puts("same"); else puts("different");
- Assume ASCII. What is printed? c int x = 'A' + 1.5; printf("%c %d", x, x);
- Given int m[3][4];, why can m not be passed to a function declared void f(int p);?