0
0
Cprogramming~5 mins

Format specifiers - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a format specifier in C?
A format specifier is a special sequence in a string that tells the program how to display or read data, like %d for integers or %f for floating-point numbers.
Click to reveal answer
beginner
What does the format specifier %d represent?
The %d specifier is used to print or read an integer (whole number) value.
Click to reveal answer
intermediate
How do you print a floating-point number with 2 decimal places in C?
Use %.2f in the format string. For example, printf("%.2f", 3.14159) prints 3.14.
Click to reveal answer
beginner
What format specifier is used to print a single character?
The %c specifier is used to print a single character.
Click to reveal answer
beginner
How do you print a string in C using format specifiers?
Use %s to print a string. For example, printf("%s", "hello") prints hello.
Click to reveal answer
Which format specifier is used to print an integer in C?
A%d
B%f
C%c
D%s
How would you print the floating-point number 3.14159 with 3 decimal places?
A%d
B%3f
C%f.3
D%.3f
What does the format specifier %c print?
AA character
BA string
CAn integer
DA floating-point number
Which format specifier is used to print a string?
A%d
B%c
C%s
D%f
What will printf("%5d", 42); print?
AAn error
B42 with 5 spaces before it
C42 with no spaces
D42 with 5 spaces after it
Explain what format specifiers are and give three examples with their uses.
Think about how you tell the program to print different types of data.
You got /4 concepts.
    Describe how to control the number of decimal places when printing a floating-point number in C.
    Focus on the dot and number inside the format specifier.
    You got /3 concepts.