0
0
Cprogramming~5 mins

Using printf for output in C - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
Aprintf("%d", num);
Bprintf("%s", num);
Cprintf("num");
Dprintf(num);
What does the \n character do in a printf string?
AEnds the program
BPrints a backslash
CPrints the letter n
DStarts a new line
How would you print the text "Hello, World!" exactly as is using printf?
Aprintf("Hello, World!\n");
Bprintf(Hello, World!);
Cprintf("Hello, World!");
Dprintf(%s, "Hello, World!");
Which format specifier is used to print a floating-point number with printf?
A%c
B%f
C%d
D%s
What will this code print? printf("%d %d", 3);
AUndefined behavior or garbage value
B3 3
C3
DError: missing argument
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.