A structured lesson workspace with readable content, hands-on examples, and a clean path to completion.
C has two comment syntaxes. // comments run to the end of the line. /* */ comments run to the closing delimiter and can span multiple lines. The // form was added in C99. Before that, only /* */ existed. Comments are stripped during translation phase 3, before preprocessing. The compiler never sees them. They are for humans. The question is not how to write comments. The question is when a comment adds value versus when it adds noise.
#include <stdio.h>/* Multi-line comment:This function computes the factorial of n.Precondition: n >= 0Postcondition: returns n!*/long factorial(int n) {long result = 1;for (int i = 2; i <= n; i++) {result *= i; // accumulate product}return result;}int main(void) {// Compute factorials for 0 through 5for (int i = 0; i <= 5; i++) {printf("%d! = %ld\n", i, factorial(i));}return 0;}
Comments that explain why, not what. "We use mmap here because the file is 4 GB and cannot fit in a malloc buffer" is valuable. "Increment i by 1" is noise. Comments that document preconditions, invariants, and non-obvious design decisions. Comments that warn about platform-specific behavior or known limitations. Comments that reference a bug tracker ID or RFC section. These survive code review and help the next reader.
A comment that describes what the code does will drift out of sync when the code changes. The comment says "returns the count of active connections" but the code now returns the count of idle connections. The reader trusts the comment and writes a bug. Stale comments are worse than no comments. If you must comment the what, make the code self-documenting instead: rename the variable, extract a function, simplify the expression. The best comment is the one you deleted because the code became clear enough to not need it.
Comment the why. Name the what. Delete the stale. Your code is read ten times more often than it is written. Every comment should earn its place by telling the reader something the code cannot. Next: error handling strategies in C, where there are no exceptions and every failure path is your responsibility.
Finish the lesson once you have worked through the material. This awards ★ 10 XP.