Recall & Review
beginner
What is the purpose of the
printf function in C?The
printf function is used to display text and variables on the screen (standard output). It helps communicate results or messages to the user.Click to reveal answer
beginner
How do you print a simple text message using
printf?Use
printf("Your message here\n"); The \n adds a new line after the message.Click to reveal answer
beginner
What does the format specifier
%d do in printf?It tells
printf to print an integer (whole number) value.Click to reveal answer
beginner
How do you print a variable value using
printf?Include a format specifier in the string and pass the variable after the string. Example:
int x = 5; printf("Value: %d\n", x);Click to reveal answer
beginner
What happens if you forget to include
\n at the end of a printf message?The output stays on the same line, so the next output will continue right after it, which can make the text hard to read.
Click to reveal answer
Which
printf statement correctly prints the integer variable num?✗ Incorrect
Use %d to print an integer variable. %s is for strings, and printing the variable name or variable directly without format specifier is incorrect.
What does the
\n character do in a printf string?✗ Incorrect
\n moves the cursor to the next line, so the next output appears below.How would you print the text "Hello, World!" exactly as is using
printf?✗ Incorrect
Plain text must be enclosed in double quotes inside
printf(). No format specifier is needed. This prints exactly "Hello, World!" without a trailing newline.Which format specifier is used to print a floating-point number with
printf?✗ Incorrect
%f is used for floating-point numbers, %d for integers, %c for characters, and %s for strings.
What will this code print?
printf("%d %d", 3);✗ Incorrect
Two %d specifiers need two integer arguments. Missing one causes unpredictable output.
Explain how to use
printf to print a message and a variable value in C.Think about how you combine text and variable values in one print statement.
You got /4 concepts.
What are some common format specifiers used with
printf and what do they print?Remember the type of data you want to show on screen.
You got /4 concepts.