Getting Started
C Introduction
What C is, why it still runs the world, and your very first program — explained line by line.
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.
#include <stdio.h>
int main(void) {
printf("Hello, World!\n");
return 0;
}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:
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:
gcc hello.c -o hello # compile hello.c into a program called hello
./hello # run itThe structure of a C program
Bigger programs follow the same skeleton. Your exam may ask you to label these parts:
/* 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;
}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
Who created the C language?
Dennis Ritchie designed C at Bell Labs in 1972 to write Unix. Stroustrup made C++, Gosling made Java and van Rossum made Python. - 2
Which function does every C program start executing from?
Execution always begins atmain. The other functions only run ifmaincalls them. - 3
Which stage of compilation joins your object file with the C library?
The linker combineshello.owith library code (likeprintf) into one executable. - 4
What does
return 0;at the end ofmainmean?By convention, a return value of 0 tells the operating system that the program ended without errors.