What does the printf()
function do in C?
a) It prints formatted output to the screen
b) It reads input from the user
c) It allocates memory dynamically
d) It closes an open file
Answer:
a) It prints formatted output to the screen
Explanation:
The printf()
function in C is used to print formatted output to the screen. It is one of the most commonly used functions for displaying text, numbers, and other data types in a human-readable format. The function uses format specifiers like %d
for integers, %f
for floats, and %s
for strings to format the output. The printf()
function is versatile and allows for precise control over how data is displayed.
Understanding printf()
is crucial for providing output in C programs, whether for debugging, user interaction, or displaying results.