Floating Point in C Programming MCQ Questions and Answers

1. Which of the following correctly states the C type used to store a single-precision IEEE-754 floating-point number?
A) double
B) float
C) long double
D) int
Answer: B

2. In C, the literal 3.14 has what type by default?
A) float
B) double
C) long double
D) long long
Answer: B

3. Which suffix makes a floating literal a float rather than a double?
A) L
B) F or f
C) LL
D) none (default is double)
Answer: B

4. Which printf conversion specifier prints a double?
A) %f
B) %lf
C) %Lf
D) %d
Answer: A (In printf, %f and %lf are equivalent.)

5. Which scanf conversion specifier reads into a float variable?
A) %f
B) %lf
C) %Lf
D) %d
Answer: A

6. Which scanf conversion specifier reads into a double *?
A) %f
B) %lf
C) %Lf
D) %g
Answer: B

7. What does DBL_EPSILON represent?
A) Smallest positive double
B) Largest double
C) Difference between 1 and next representable double > 1
D) Mantissa bit count
Answer: C

8. On most systems, sizeof(float) is:
A) 2
B) 4
C) 8
D) 16
Answer: B

9. For IEEE-754, which is true?
A) NaN == NaN true
B) NaN != NaN true
C) NaN < any number true
D) NaN equals 0
Answer: B

10. Which macro gives the maximum finite float value?
A) FLT_MAX
B) FLT_MIN
C) DBL_MAX
D) FLT_EPSILON
Answer: A

11. What does FLT_MIN denote?
A) Smallest positive normalized float
B) Most negative float
C) Subnormal minimum
D) Machine epsilon
Answer: A

12. To force single-precision arithmetic:
A) Use 3.14
B) Use 3.14f
C) Cast to double
D) Append L
Answer: B

13. Assigning double → float causes:
A) Promotion
B) Integer truncation
C) Possible rounding/precision loss
D) Error
Answer: C

14. Function splitting value into mantissa/exponent (base 2)?
A) frexp
B) ldexp
C) modf
D) fmod
Answer: A

15. Inverse of frexp?
A) ldexp
B) modf
C) scalbn
D) exp2
Answer: A (Note: ldexp is inverse.)

16. What does modf do?
A) Integer remainder
B) Split into integer & fractional parts
C) Modulo two floats
D) Round to int
Answer: B

17. Subnormal number =
A) Magnitude < smallest normalized value, reduced precision
B) Max float
C) Infinity
D) Zero
Answer: A

18. FLT_MANT_DIG means:
A) Decimal digits
B) Bits in mantissa
C) Rounding mode
D) Exponent bits
Answer: B

19. FLT_DIG gives:
A) Decimal digits precision of float
B) Mantissa bits
C) Base
D) Round mode
Answer: A

20. How to test for NaN?
A) x == x
B) isnan(x)
C) x > x
D) x < 0
Answer: B

21. Check for infinity:
A) isinf(x) or x == INFINITY
B) x == FLT_MAX
C) x > 1e308
D) x == NAN
Answer: A

22. At -O2, floating optimizations may:
A) Always preserve IEEE rounding
B) Reassociate & change rounding slightly
C) Disable FP
D) Convert to ints
Answer: B

23. Header for isnan()?
A) <stdio.h>
B) <math.h>
C) <float.h>
D) <stdlib.h>
Answer: B

24. 1.0f / 0.0f gives:
A) Compile error
B) +INFINITY (runtime)
C) NaN
D) Undefined behavior (though IEEE yields INF)
Answer: D

25. Near-equality test:
A) a==b
B) fabs(a-b)<EPS
C) a>b
D) a-b==0
Answer: B

26. printf for long double:
A) %f
B) %lf
C) %Lf
D) %llf
Answer: C

27. About rounding modes:
A) Only round-to-zero
B) Changeable via <fenv.h>
C) Fixed by C standard
D) Irrelevant to sqrt
Answer: B

28. Header controlling FP environment:
A) <math.h>
B) <fenv.h>
C) <errno.h>
D) <float.h>
Answer: B

29. FP exception macros include:
A) FE_OVERFLOW, FE_DIVBYZERO, etc.
B) FE_IOERROR
C) FE_DIVIDE
D) FE_SYMBOL
Answer: A

30. (float)(1<<30) causes:
A) Exact result
B) Rounding possible
C) NaN
D) Undefined
Answer: B

31. fesetround(FE_TONEAREST) means:
A) Set rounding to nearest-even
B) Make all floats integer
C) Clear flags
D) No effect
Answer: A

32. Why not exact 0.1?
A) Irrational
B) Repeating binary fraction
C) > FLT_MAX
D) Exact
Answer: B

33. Remainder function?
A) fmod(x,y)
B) remainder
C) modf
D) floor
Answer: A

34. Difference fmod vs remainder:
A) Identical
B) remainder uses nearest multiple; fmod keeps sign of x
C) remainder always positive
D) fmod integer only
Answer: B

35. %g does what?
A) Chooses %f or %e whichever shorter
B) Integer print
C) Binary
D) Identical to %Lf
Answer: A

36. FLT_EPSILON in:
A) <math.h>
B) <limits.h>
C) <float.h>
D) <stdint.h>
Answer: C

37. FLT_EPSILON =
A) Smallest normalized float
B) Max float
C) 1 – next representable >1
D) Exp bits
Answer: C

38. float + double →
A) Promotes float to double
B) Demotes double
C) Error
D) long double result
Answer: A

39. Best precision printing:
A) %.9g or %.17g
B) %f default
C) puts
D) itoa
Answer: A

40. Float arithmetic must:
A) Exactly follow IEEE always
B) Follow C rules; IEEE optional
C) Only software
D) Overflow compile-time
Answer: B

41. Fractional part:
A) x – floor(x)
B) x / floor(x)
C) ceil(x)
D) modf(x)
Answer: A

42. modf(x,&intpart) returns:
A) int part
B) fractional part
C) remainder
D) NaN
Answer: B

43. Next representable after x toward y:
A) nextafter
B) nextafterf
C) nexttoward
D) All (type-dependent)
Answer: D

44. Quiet vs signaling NaN:
A) All signaling
B) Quiet propagate silently; signaling may raise exception
C) None exist
D) Equals zero
Answer: B

45. <fenv.h> added in:
A) C89
B) C99
C) C11
D) None
Answer: B

46. Equality best practice:
A) ==
B) Relative tolerance check
C) Compare strings
D) Convert to int
Answer: B

47. printf(“%f”, (float)3.14);
A) UB
B) Works (promoted to double)
C) Compile error
D) Prints int
Answer: B

48. Next float toward +∞:
A) nextafterf(x, INFINITY)
B) nexttowardf(x,1.0L)
C) nextafter(x,1.0)
D) pow(x,y)
Answer: A

49. Overflow →
A) Abort
B) Sets overflow flag, result ±INF (usually)
C) Wrap
D) Zero
Answer: B

50. fesetenv(FE_DFL_ENV)
A) Reset FP env to default
B) Freeze registers
C) Zero floats
D) Clear OS env
Answer: A

51. Machine epsilon for double:
A) DBL_MIN
B) DBL_EPSILON
C) DBL_MAX
D) FLT_EPSILON
Answer: B

52. long double precision:
A) Always 128-bit
B) Implementation-defined
C) Same as double always
D) Integer-only
Answer: B

53. Cast (int)f truncates toward:
A) Nearest
B) Zero
C) Negative
D) Infinity
Answer: B

54. frexpf:
A) Float version of frexp
B) Factorial
C) Round
D) Nonstandard
Answer: A

55. To print long double:
A) %Lf
B) %f
C) %lf
D) None
Answer: A

56. Macro INFINITY found in:
A) <stdlib.h>
B) <math.h>
C) <float.h>
D) <stdio.h>
Answer: B

57. Floating I/O identical across platforms?
A) Always
B) Can differ unless format fixed
C) Always max precision
D) Locale-independent
Answer: B

58. DBL_MANT_DIG =
A) Bits in mantissa
B) Decimal digits
C) Exponent bits
D) Size in bytes
Answer: A

59. Next long double value:
A) nexttowardl
B) nextafter
C) nextafterf
D) ldexp
Answer: A

60. %a format does what?
A) Prints hex FP form
B) Nonstandard
C) ASCII art
D) Integer
Answer: A

61. Why %a useful?
A) Shows exact binary in hex
B) Converts to int
C) Rounds
D) Hides error
Answer: A

62. Implicit bit significance:
A) Hidden bit = 1 for normals
B) Always 0
C) Adds to exponent
D) Sign bit
Answer: A

63. round(x) rounds:
A) Half away from zero
B) Toward zero
C) Up always
D) Even
Answer: A

64. trunc(x) rounds:
A) To nearest
B) Toward zero
C) Up
D) Down
Answer: B

65. fabs vs fabsf:
A) double vs float
B) int
C) opposite types
D) identical always
Answer: A

66. Detect IEEE-754 portability:
A) No guaranteed way; test macros/runtime
B) #ifdef IEEE754
C) Check size only
D) Assume always
Answer: A

67. FLT_RADIX =
A) Base (usually 2)
B) Exponent bits
C) Rounding
D) Max value
Answer: A

68. (1e20+1)-1e20 =
A) 1
B) 0 (precision loss)
C) NaN
D) INF
Answer: B

69. Best summation accuracy:
A) Left-to-right
B) Kahan summation
C) Cast to int
D) Random
Answer: B

70. Same code, different compilers → different FP results due to:
A) Optimizations, precision differences
B) Only integers
C) Identical always
D) None
Answer: A

71. __FLT_DENORM_MIN__ gives:
A) Min positive subnormal float
B) Not related
C) Max float
D) Rounding mode
Answer: A

72. Print float with 6 decimals:
A) printf(“%.6f”, f)
B) %f
C) %6f
D) %d
Answer: A

73. %g default precision:
A) 6 significant digits
B) 15 digits
C) Integer
D) Binary
Answer: A

74. Avoid FP exceptions:
A) Use integer/guarded math
B) Ignore
C) goto
D) printf
Answer: A

75. sqrt(-1.0) →
A) NaN, FE_INVALID
B) INF
C) 0
D) Complex
Answer: A

76. ldexp(x,n) computes:
A) x * 2^n
B) log2(x)
C) trunc(x,n)
D) mod
Answer: A

77. frexp returns:
A) Mantissa & exponent
B) Only int part
C) Only exp
D) log2
Answer: A

78. 1e-40f likely:
A) double
B) float (maybe subnormal)
C) long double
D) int
Answer: B

79. Compare to zero?
A) Always safe
B) Prefer threshold test
C) Never use fabs
D) Convert to int
Answer: B

80. In varargs, float →
A) float
B) promoted to double
C) long double
D) int
Answer: B

81. volatile and FP:
A) Prevents reordering, not rounding changes
B) Makes double
C) Removes error
D) Ignored
Answer: A

82. Different long double results because:
A) Impl-defined formats
B) Always 256-bit
C) Always int
D) Always same
Answer: A

83. %e prints:
A) Scientific notation
B) Integer
C) Binary
D) Hex
Answer: A

84. Floating addition associativity:
A) Always true
B) Not guaranteed (rounding)
C) Always false
D) Integer only
Answer: B

85. Reproducible FP results:
A) Fix IEEE semantics, flags, libs
B) Random
C) Different compilers
D) Defaults
Answer: A

86. FE_ALL_EXCEPT:
A) Represents all FP exceptions
B) Rounding
C) Integer
D) Not FP
Answer: A

87. Math functions & errno:
A) Some set errno (legacy), check math_errhandling
B) printf sets errno
C) atoi sets errno
D) None
Answer: A

88. #pragma STDC FP_CONTRACT ON:
A) Allow fused multiply-add
B) Disable FP
C) Force int
D) None
Answer: A

89. Convert string to double safely:
A) strtod()
B) atoi()
C) scanf()
D) printf()
Answer: A

90. %lf in printf:
A) Equivalent to %f (ignored)
B) Required
C) long long
D) Undefined
Answer: A

91. Normalized vs subnormal:
A) Normal has implicit 1; subnormal doesn’t
B) Subnormal infinite
C) Normal integer
D) Subnormal NaN
Answer: A

92. Round toward −∞:
A) floor()
B) ceil()
C) trunc()
D) round()
Answer: A

93. signbit(x) tests:
A) Sign bit set (true for −0, negatives)
B) x<0
C) NaN only
D) Positive only
Answer: A

94. Divide −0.0/2 →
A) −0.0
B) +0.0
C) NaN
D) Undefined
Answer: A

95. Integer division vs FP division:
A) Different operators
B) / same, but type decides
C) Identical
D) Always integer
Answer: B

96. Compiler option for IEEE strictness:
A) -fno-fast-math (GCC/Clang)
B) -Ofast
C) -march
D) none
Answer: A

97. Rounding toward +∞:
A) ceil()
B) floor()
C) trunc()
D) round()
Answer: A

98. pow(0, -1) →
A) INF, FE_DIVBYZERO
B) 0
C) NaN
D) 1
Answer: A

99. hypot(x,y) avoids overflow by:
A) Scaling internally
B) Using xx + yy directly
C) Integer math
D) None
Answer: A

100. Floating constants compared with == :
A) Unsafe for precision loss
B) Always accurate
C) Only for NaN
D) Integer safe
Answer: A