Challenge - 5 Problems
Printf Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of printf with mixed format specifiers
What is the output of the following C code?
C
#include <stdio.h> int main() { int a = 5; float b = 3.2f; printf("%d %.1f\n", a, b); return 0; }
Attempts:
2 left
💡 Hint
Look at the format specifiers %d and %.1f and how they control output.
✗ Incorrect
The %d prints the integer 5 as '5'. The %.1f prints the float with one decimal place, so 3.2 is printed as '3.2'.
❓ Predict Output
intermediate2:00remaining
Output of printf with escape sequences
What will this C program print?
C
#include <stdio.h> int main() { printf("Hello\nWorld\t!\n"); return 0; }
Attempts:
2 left
💡 Hint
Remember \n is new line and \t is tab (spaces).
✗ Incorrect
The \n creates a new line, so 'Hello' and 'World' appear on separate lines. The \t adds a tab space before '!'.
🔧 Debug
advanced2:00remaining
Identify the error in printf usage
What error will this code produce when compiled or run?
C
#include <stdio.h> int main() { int x = 10; printf("Value is %d %f", x); return 0; }
Attempts:
2 left
💡 Hint
Check how many arguments printf expects vs provided.
✗ Incorrect
The format string expects two arguments (%d and %f), but only one (x) is provided. This causes undefined behavior and prints garbage for %f.
🧠 Conceptual
advanced2:00remaining
Understanding printf return value
What does the printf function return after printing successfully?
Attempts:
2 left
💡 Hint
Think about what information printf might give back after printing.
✗ Incorrect
printf returns the number of characters it successfully printed to the output.
📝 Syntax
expert2:00remaining
Which printf statement compiles and prints correctly?
Choose the option that compiles without error and prints exactly: 3.14
Attempts:
2 left
💡 Hint
Check the correct syntax for floating point precision in printf.
✗ Incorrect
Option A uses %.2f which prints a float with 2 decimal places. Others have syntax errors or wrong specifiers.