ProgrammingVery hardProduct company OA
Assume IEEE-754 float (24-bit significand) and 32-bit int. What is printed?
Assume IEEE-754 float (24-bit significand) and 32-bit int. What is printed?
int big = 16777217; /* 2^24 + 1 */
float f = big;
printf("%d", (int)f == big);- A. 16777217
- B. Undefined behaviour
- C. 1
- D. 0
Correct answer: D. 0
A float holds 24 significant bits, so integers above 2^24 are not all representable; 2^24 + 1 rounds to 2^24 = 16777216. Converting back gives 16777216, which is not equal to big. The conversion is well defined because the value is in range for float.
More C Programming questions
- Assume 8-bit unsigned char. What is printed? c int i; unsigned char c; double d; d = c = i = 300 + 0.7; printf("%d %d %.1f", i, c, d);
- Why is memcmp(&a, &b, sizeof a) == 0 an unreliable way to test whether two struct variables a and b have equal members?
- What is printed? c int c = 0; int f(int n) { c++; return n > 0 && (f(n - 1) || f(n - 2)); } int main(void) { int r = f(4); printf("%d %d"…
- What is printed? c char buf[32], p = buf; for (int i = 1; i <= 4; i++) p += sprintf(p, "%d,", i i); p[-1] = '0'; printf("%s %td", buf, p…
- How many swaps does this selection sort perform? c int a[] = {3, 1, 2, 5, 4}, sw = 0; for (int i = 0; i < 4; i++) { int m = i; for (int j…
- How many element shifts (executions of a[j + 1] = a[j]) does this insertion sort make? c int a[] = {4, 3, 2, 1}, shifts = 0; for (int i =…