0
0
Cprogramming~20 mins

Using printf for output in C - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Printf Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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;
}
A5 3
B5.0 3.2
C5 3.20
D5 3.2
Attempts:
2 left
💡 Hint
Look at the format specifiers %d and %.1f and how they control output.
Predict Output
intermediate
2: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;
}
A
Hello
World    !
B
Hello
World	!
CHello World !
DHelloWorld!\n
Attempts:
2 left
💡 Hint
Remember \n is new line and \t is tab (spaces).
🔧 Debug
advanced
2: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;
}
ACompilation error: missing argument for %f
BRuntime error: segmentation fault
COutput: Value is 10 (garbage value)
DOutput: Value is 10 0.000000
Attempts:
2 left
💡 Hint
Check how many arguments printf expects vs provided.
🧠 Conceptual
advanced
2:00remaining
Understanding printf return value
What does the printf function return after printing successfully?
AAlways zero
BThe number of characters printed
CThe last character printed
DA pointer to the output string
Attempts:
2 left
💡 Hint
Think about what information printf might give back after printing.
📝 Syntax
expert
2:00remaining
Which printf statement compiles and prints correctly?
Choose the option that compiles without error and prints exactly: 3.14
Aprintf("%.2f", 3.14159);
Bprintf("%2.f", 3.14159);
Cprintf("%f.2", 3.14159);
Dprintf("%.2d", 3.14159);
Attempts:
2 left
💡 Hint
Check the correct syntax for floating point precision in printf.