Trace One Tiny C Program
Follow one printed sign
The workshop needs a sign that says Repair desk open. This is a complete program, so you can run it without filling anything in. The Run block is a worked example, not an editable exercise. First read the trace below it; then press Run and compare the output.
#include <stdio.h>
int main(void) {
printf("Repair desk open\n");
return 0;
}
Read the parts in order
#include <stdio.h> includes the standard input/output header during the build. A header supplies declarations: information the compiler needs about names such as printf and how to call them. Including the header does not call printf or print anything.
A function is a named piece of work. main is the starting function for these programs. In int main(void), int says it returns a whole-number status, and void says this form takes no arguments. The braces { and } enclose its body: the statements it runs.
- Execution enters
main. printf("Repair desk open\n");calls the printing function. Calling means asking that function to do its work. The text inside parentheses is an argument, a value passed to the function.- The text in double quotes is a string literal, meaning text written directly in the source. The quotes themselves do not print.
\nends the output line. - After
printffinishes, execution continues atreturn 0;. This endsmainand reports success to the environment. It does not print a zero.
The semicolons finish the two statements inside main. #include is a build instruction, not one of those statements, so it has no semicolon.
The output should contain one sign line. In the next exercise, you'll add printing statements yourself.