Help improve SovranCode?

Google Analytics can measure anonymous usage after you choose Allow. Essential account and progress features work either way.

SovranCode
C: Foundations for Systems Programming What C Is and How C Programs Run
This device
Course contentsWhat C Is and How C Programs Run · 15 titles

C foundations

What C Is and How C Programs RunYour First C ProgramVariables, Types, and OperatorsInput and Output with printf and scanfConditions and Loops

Program structure and data

Functions, Headers, and ScopeArrays and StringsPointers and Memory AddressesStructures, Enumerations, and UnionsFiles and Command-Line Arguments

Memory, tooling, and practice

Dynamic Memory AllocationPreprocessor Directives and Separate CompilationErrors, Debugging, and Undefined BehaviorBuild Tools and MakefilesProject: Command-Line Inventory Manager
C: Foundations for Systems Programming15 complete lessons

C foundations

What C Is and How C Programs RunYour First C ProgramVariables, Types, and OperatorsInput and Output with printf and scanfConditions and Loops

Program structure and data

Functions, Headers, and ScopeArrays and StringsPointers and Memory AddressesStructures, Enumerations, and UnionsFiles and Command-Line Arguments

Memory, tooling, and practice

Dynamic Memory AllocationPreprocessor Directives and Separate CompilationErrors, Debugging, and Undefined BehaviorBuild Tools and MakefilesProject: Command-Line Inventory Manager
COURSE OVERVIEWC: Foundations for Systems Programming
NEXT LESSONYour First C Program
C fundamentals 50 min

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.

What you will leave with

You will be able to identify a C source file, explain the jobs of the preprocessor, compiler, linker, and operating system, read a minimal main function, produce terminal output, use a warning-enabled local build command, repair a syntax mistake, and state the difference between a declaration and an implementation.

Map the system before learning the details

SourceRecognize a .c file as human-written program text.
ToolchainExplain preprocessing, compilation, and linking as distinct stages.
RuntimeFollow control into main and then to terminal output.
DebuggingUse the first precise diagnostic to make one small repair.

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.

Use precise language

The C language defines rules for source code. A compiler diagnoses and translates that code. A linker combines compiled pieces and libraries. The operating system loads the resulting executable and starts it. Keeping those roles separate makes errors far easier to understand.

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.

  1. 01
    Write source

    You save readable instructions in a file such as hello.c.

  2. 02
    Preprocess and compile

    Directives such as #include are handled, then C source is translated into object code while the compiler reports syntax and type problems it can detect.

  3. 03
    Link

    The linker combines your object code with required library code, including the implementation behind standard-library calls such as printf.

  4. 04
    Load 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.

C FUNDAMENTALS RUNNER

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.

#include <stdio.h>

int main(void) {
  printf("Hello, SovranCode!\n");
  return 0;
}
TERMINAL OUTPUT
Edit the program, predict its output, then run it.

This safe browser runner supports the lesson subset: scalar and fixed-size int/double arrays, character strings, indexed reads and numeric writes, arithmetic, printf/puts, numeric scanf into scalar or bounded array-element addresses, comparisons, bounded if/else, for/while loops, and return.

Try this next: Add a second printf line before return 0; and make sure each statement ends with a semicolon.

Read the program line by line

#include <stdio.h>

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.

int main(void)

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.

printf(...);

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.

return 0;

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.

C FUNDAMENTALS RUNNER

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.

#include <stdio.h>

int main(void) {
  int sessions = 4;
  int completed = 1;
  int remaining = sessions - completed;

  printf("Remaining sessions: %d\n", remaining);
  return 0;
}
TERMINAL OUTPUT
Edit the program, predict its output, then run it.

This safe browser runner supports the lesson subset: scalar and fixed-size int/double arrays, character strings, indexed reads and numeric writes, arithmetic, printf/puts, numeric scanf into scalar or bounded array-element addresses, comparisons, bounded if/else, for/while loops, and return.

Try this next: Change the format text and add a second integer calculation using +, -, *, /, or %.

Do not hide warnings

Compilers can build code that is legal but suspicious. Warnings are evidence about a possible mismatch between your intent and the source. Build with warnings enabled, read them, and avoid treating a successful executable as proof that the program is correct.

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.

macOSInstall command-line tools once, then use Clang.xcode-select --installclang -Wall -Wextra -Wpedantic hello.c -o hello./hello
LinuxUse your distribution’s C compiler package, commonly GCC or Clang.gcc -Wall -Wextra -Wpedantic hello.c -o hello./helloIf gcc is unavailable, install your distribution’s build tools package first.
WindowsUse a Visual Studio Developer Command Prompt or another configured toolchain.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.

C FUNDAMENTALS RUNNER

Find the missing boundary

Read the runner message before changing the source. Repair the smallest possible part, then run it again.

#include <stdio.h>

int main(void) {
  printf("The compiler needs punctuation.\n")
  return 0;
}
TERMINAL OUTPUT
Edit the program, predict its output, then run it.

This safe browser runner supports the lesson subset: scalar and fixed-size int/double arrays, character strings, indexed reads and numeric writes, arithmetic, printf/puts, numeric scanf into scalar or bounded array-element addresses, comparisons, bounded if/else, for/while loops, and return.

Try this next: After it runs, deliberately remove the final } and compare that structural error with the missing-semicolon error.

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.

C FUNDAMENTALS RUNNER

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.

#include <stdio.h>

int main(void) {
  const char *learner = "Ada";

  printf("Welcome, %s!\n", learner);
  puts("C turns source into a program.");
  return 0;
}
TERMINAL OUTPUT
Edit the program, predict its output, then run it.

This safe browser runner supports the lesson subset: scalar and fixed-size int/double arrays, character strings, indexed reads and numeric writes, arithmetic, printf/puts, numeric scanf into scalar or bounded array-element addresses, comparisons, bounded if/else, for/while loops, and return.

Try this next: Introduce yourself, keep a newline at the end of each message, and predict the final terminal output before running 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 uses printf.
  • 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.
KNOWLEDGE CHECK

Explain the path from source to output

Answer every question, then use the explanations to test your mental model. A perfect score is useful, but an explanation you can repeat in your own words is the goal.

01What does a C compiler primarily produce from a source file?
02Why does a program that calls printf usually include <stdio.h>?
03Which function is the normal entry point where a hosted C program begins?
04What does the escape sequence \n do inside a C string literal?
05When a build reports an error near a line, what is the most reliable first move?
COURSE OVERVIEWC: Foundations for Systems Programming
NEXT LESSONYour First C Program
ON THIS PAGEWhat C Is and How C Programs RunLesson mapWhat C isSource to executionRun a first programRead main line by lineOutput with printfCompile locallyRepair an errorIndependent labLesson reviewKnowledge check
Course contents