A structured lesson workspace with readable content, hands-on examples, and a clean path to completion.
The percent sign is printf's escape character. It introduces every format specifier: %d, %s, %f. If you want to print a literal percent sign, you cannot just write "%". printf sees the percent and expects a specifier to follow. The solution is %%: two percent signs produce one literal percent in the output. This is the only escape mechanism in printf format strings. There is no backslash escape for percent.
#include <stdio.h>int main(void) {printf("Progress: 75%%\n");printf("Discount: %d%% off\n", 20);printf("Battery: %d%% remaining\n", 42);int pass = 18, total = 20;double pct = (double)pass / total * 100.0;printf("Score: %d/%d (%.1f%%)\n", pass, total, pct);return 0;}
Every %% in the format string becomes a single % in the output. The format specifiers %d and %.1f work normally alongside the escaped percents. If you write a single % followed by a space or a non-specifier character, the behavior is undefined. Some compilers print garbage. Some crash. Always double the percent.
#include <stdio.h>int main(void) {printf("Bad: 50% complete\n");return 0;}
GCC warns about the trailing percent. The output dropped the percent sign entirely. On another platform or compiler, the output could be different. The warning is your friend. Fix it by writing 50%%.
A tiny lesson for a tiny problem, but one that trips up every C programmer at least once. You are building a progress bar. You type printf("%d%", progress). The compiler warns. You stare at it for thirty seconds. Then you remember: %%. Next: isprint, for testing whether a character is printable.
Finish the lesson once you have worked through the material. This awards ★ 10 XP.