What C Is and How C Programs Run
C is a compiled language: you write a source file, a toolchain turns it into a program for a specific environment, and that program runs outside the browser. Before adding more syntax, learn the complete path that makes a tiny C program real.
Map the system before learning the details
.c file as human-written program text.main and then to terminal output.What C is—and what it is not
C is a general-purpose programming language with a small core and a close relationship to the memory and operating-system services beneath many programs. Operating systems, embedded devices, databases, tools, and performance-sensitive libraries often use it because C gives programmers direct control over data representation and program boundaries.
C source is not executed directly by a web browser. A C implementation—commonly a compiler plus a linker—translates source into an executable for a target environment. That distinction matters: a source file can be portable in intent, while the executable is built for a particular operating system and processor combination.
Follow one program through its lifecycle
For a first program, think in four visible hand-offs. Toolchains combine or optimize some of these steps, but the responsibilities stay useful to name.
- 01Write source
You save readable instructions in a file such as
hello.c. - 02Preprocess and compile
Directives such as
#includeare handled, then C source is translated into object code while the compiler reports syntax and type problems it can detect. - 03Link
The linker combines your object code with required library code, including the implementation behind standard-library calls such as
printf. - 04Load and run
Your operating system starts the executable, the C runtime reaches
main, and your statements create observable output or effects.
Errors point to different stages. A missing semicolon is usually a compiler diagnostic. A missing function implementation may be a linker error. A program that starts but behaves wrongly is a runtime or logic problem. Read the stage first; it tells you where to investigate.
Run a first C program
The program below includes the declarations for standard input/output, defines the conventional entry function, asks printf to display a line, and returns a success status. Predict the terminal text before you run it. Then replace the greeting and run it again.
Your first C program
This is a small, linear C program. Change only the words inside the double quotes, predict what the terminal will show, then run it.
Edit the program, predict its output, then run it.
Read the program line by line
Ask for declarations
#include is a preprocessor directive, not a runtime function call. It makes declarations from the standard input/output header available so the compiler knows how printf is meant to be called.
Define the entry point
In a hosted C program, execution begins in main. The int says it returns an integer status. void says this version receives no parameters.
Make output observable
printf sends formatted text to standard output. The final \n asks for a new terminal line; the semicolon ends the C statement.
Finish successfully
An explicit zero status conventionally signals success to the environment. Reaching the end of main is also equivalent to returning zero in modern hosted C, but writing it makes the program’s exit status visible while learning.
Use output deliberately
printf is useful because its format string can combine ordinary text with values. The placeholder %d requests an integer, and the following argument supplies that integer. The format and the supplied values must agree—later lessons will cover types in depth, so treat that pairing as an important contract from the beginning.
Display a calculated integer
Change sessions or completed, predict remaining, then run it. The runner supports the small C subset used here so you can focus on the source-to-output flow.
Edit the program, predict its output, then run it.
Compile the same source locally
The browser runner is intentionally limited to the concepts in this lesson. A local compiler is the authority for real C code because it knows your system, target, libraries, and full language features. Save the first example as hello.c, then use the command appropriate to your environment.
xcode-select --installclang -Wall -Wextra -Wpedantic hello.c -o hello./hellogcc -Wall -Wextra -Wpedantic hello.c -o hello./helloIf gcc is unavailable, install your distribution’s build tools package first.cl /W4 hello.chello.exeThe exact install command depends on your chosen toolchain; the build and run steps are the same idea.The warning flags are deliberately strict: -Wall and -Wextra ask for common warning groups, while -Wpedantic asks for warnings about non-standard extensions. They help you form the habit of fixing evidence early.
Repair one compiler error
This program has one missing semicolon after the printf call. The runner reports the same category of mistake a compiler will: it cannot determine where that statement ends. Add only the semicolon, run again, and notice how a one-character repair restores the whole program.
Find the missing boundary
Read the runner message before changing the source. Repair the smallest possible part, then run it again.
Edit the program, predict its output, then run it.
Independent lab: make a terminal welcome
Now work without copying a prior output. Change the learner name, write a second sentence with puts, then add one more printf line. Keep the header, main signature, braces, and return 0; intact. Run the result and explain which line creates each terminal line.
Build a two-line welcome
Use the source as a starting point, but make the wording your own. The output should have at least two readable lines.
Edit the program, predict its output, then run it.
Lesson review
You now have the key orientation for the rest of C: source is not the executable, headers provide declarations, the compiler and linker have different jobs, the runtime reaches main, and terminal output comes from deliberate function calls. Use the checklist to decide whether the next lesson will build on a real understanding.
- I can name the source, compiler, linker, executable, and runtime stages in order.
- I can explain why
#include <stdio.h>appears before a program that usesprintf. - I can identify the entry point, a statement boundary, a newline escape, and an exit status.
- I can run a warning-enabled local build and use a diagnostic to make one small repair.