C Workshop · Introduction to C
Foundation C

Introduction to C

C is a compiled language. You write source, a compiler turns it into machine code, then the CPU runs that file.

What it is

C is a language you write as text, then a compiler turns into a program the computer can actually run. Nothing happens until you compile and then start that program. This page is that whole journey in one picture: write, compile, run, see output.

Approach

  1. Write a .c source file with #include, main, and statements.
  2. Compile with gcc hello.c -o hello. Fix any errors the compiler prints.
  3. Run the executable. printf sends text to standard output.
  4. Return 0 from main to tell the OS the program succeeded.

Where this is used in the real world

Diagram

1

Source hello.c

plain text you type

The compiler has not run yet.
2

gcc / clang

translate to machine code

Errors here are compile-time, not runtime.
3

Executable

a file the OS can load

On Windows this is often hello.exe.
4

Run

CPU executes main()

printf sends characters to the terminal.
5

Output

Hello, Kodin!

return 0 tells the OS the program succeeded.

Run algorithm

Each step highlights the matching C line. Program output appears only when a line that prints actually runs.

Ready
C code
1#include <stdio.h>
2int main(void) {
3  printf("Hello, Kodin!\n");
4  return 0;
5}
What this line does
Press Run algorithm. The highlight will move through the C code.
Program output
(no output yet)

Check your understanding

Five questions. Pick one answer each, then Check answers. The correct choice turns green.

1. What does gcc do to hello.c?

C is compiled. gcc writes a machine-code file you then run.

2. Where does a hosted C program start?

The operating system calls main.

3. What does return 0 from main usually mean?

By convention 0 means success.

4. A .c file by itself is:

Source is text until you compile.

5. printf is declared in which header?

Standard input/output lives in stdio.h.