Difficulty: Easy
Correct Answer: Yes
Explanation:
Introduction / Context:
Converting numbers to text is a routine task. This question asks whether C provides ways to express integers or floating-point values as strings.
Given Data / Assumptions:
int
or float/double
.
Concept / Approach:
Yes. Standard C offers formatted I/O functions such as sprintf
and snprintf
to write formatted numbers into a character buffer. Many platforms also provide non-standard helpers such as itoa
, ftoa
, or gcvt
; however, portable code should prefer snprintf
with appropriate format specifiers like %d
, %ld
, %f
, %.2f
, etc.
Step-by-Step Solution:
Verification / Alternative check:
Print the buffer or compare with printf
output; both use the same formatting rules.
Why Other Options Are Wrong:
No: Incorrect; standard formatted output routines exist precisely for this purpose.
Common Pitfalls:
sprintf
without bounds checking; prefer snprintf
.itoa
in cross-platform code.
Final Answer:
Yes
Discussion & Comments