Bytebook Compiler

Getting Started

C Introduction

What C is, why it still runs the world, and your very first program — explained line by line.

4 min read2 runnable examples4-question quiz

C is a general-purpose programming language created by Dennis Ritchie at Bell Labs in 1972. It was built to write the Unix operating system, and today it still runs underneath almost everything: Linux and Windows kernels, Python's interpreter, databases like MySQL, microcontrollers in washing machines and cars.

C is small, fast and close to the hardware. You decide where every byte of memory goes. That makes it the perfect first language for a computer science student: once you understand C, every other language makes more sense.

Your first C program

Every C journey starts with the same program. Read it, then press Try it Yourself to run and edit it.

C
#include <stdio.h>

int main(void) {
    printf("Hello, World!\n");
    return 0;
}
Output
Hello, World!

Here is what each line does:

Line Meaning
#include <stdio.h> Brings in the standard input/output library, which contains printf.
int main(void) Every C program starts running at main. It returns an int to the operating system.
{ ... } Curly braces group statements into a block — here, the body of main.
printf("Hello, World!\n"); Prints text. \n moves to a new line. Every statement ends with ;.
return 0; Ends main and tells the OS the program finished successfully.

From source code to a running program

Your computer's processor cannot run C directly — it only understands machine code. A compiler such as gcc translates your file in four stages:

hello.c — the code you writePreprocessor: expands #include and #defineCompiler: turns C into assemblyAssembler: turns assembly into machine code (hello.o)Linker: joins hello.o with the C libraryhello — a program you can run
The four stages that gcc hello.c -o hello runs for you.

On your own machine (Linux, macOS, or Windows with MinGW/WSL) you compile and run like this:

Terminal
gcc hello.c -o hello     # compile hello.c into a program called hello
./hello                  # run it

The structure of a C program

Bigger programs follow the same skeleton. Your exam may ask you to label these parts:

C
/* 1. Documentation: what this program does */
// Prints the area of a circle

/* 2. Preprocessor directives */
#include <stdio.h>
#define PI 3.14159

/* 3. Global declarations */
double area(double r);

/* 4. The main function */
int main(void) {
    double r = 2.0;
    printf("Area = %.2f\n", area(r));
    return 0;
}

/* 5. User-defined functions */
double area(double r) {
    return PI * r * r;
}
Output
Area = 12.57

Where C is used today

  • Operating systems — the Linux kernel is about 30 million lines of C.
  • Embedded systems — microcontrollers in cars, routers, smart TVs and medical devices.
  • Language runtimes — CPython, the Ruby interpreter and parts of Node.js are written in C.
  • Databases and networking — SQLite, MySQL, Redis, curl and most network stacks.

Test yourself

4 questions · pick an answer to check it instantly

  1. 1

    Who created the C language?

  2. 2

    Which function does every C program start executing from?

  3. 3

    Which stage of compilation joins your object file with the C library?

  4. 4

    What does return 0; at the end of main mean?