Introduction to C and Your First Program
Understand how a C program becomes a running application, then write 4 working programs using main() and printf().
Concepts
What is programming?
Writing step-by-step instructions that a computer can follow to solve a problem.
Where is C used?
Operating systems, embedded devices, game engines, databases, drivers and the tools other languages are built on.
Source code
The human-readable text you write, saved in a file ending with .c.
Compiler vs interpreter
A compiler translates the whole program first. An interpreter translates and runs it line by line.
Compiler vs Interpreter
| Feature | Compiler (C) | Interpreter (e.g. Python) |
|---|---|---|
| Translation | Whole program at once | Line by line while running |
| Output | Executable file | No separate executable (usually) |
| Speed at run time | Usually faster | Usually slower |
| Errors | Shown before the program runs | Shown when that line runs |
How Source Code Becomes a Program
Click a stage to see what happens and the gcc command that shows it.
Program Anatomy
Click any line to see what it does.
Exercise 1: Install or Open a C Compiler
Verify with gcc --version. Compile with gcc hello.c -o hello, then run ./hello (Windows: hello.exe).
Command Cheat Sheet
Type these in a terminal (Command Prompt, PowerShell, Terminal). Commands are coloured: command -flag file.c. Click Copy to copy one.
| Command | What it does | Where |
|---|
Exercises 2-4: Your 4 Programs
Each program shows its code and the output produced by the built-in simulator. Download the file, compile it on your own computer, and tick it off.
Printf Reference
| Specifier | Prints | Example |
|---|---|---|
%d | Integer | 42 |
%f / %.2f | Decimal number | 3.14 |
%c | One character | A |
%s | String | Riya |
%-10s / %5d | Left / right aligned width | padding |
%% | A percent sign | % |
| Escape | Meaning |
|---|---|
\n | New line |
\t | Tab |
\\ | Backslash |
\" | Double quote |
Live C Playground: Auto-Run, Errors and Fixes
Every C program must start at main(). Type C code below: it is colour-highlighted, checked and run on every keystroke. Supports printf, scanf, int/float/char variables, char name[N] text and basic maths. Turn on Smart suggestions for autocomplete, and use Format code to tidy any code into a clean structure. if/for/while come in later lessons.
Smart suggestions are on. Click inside the code, type pr and choose a suggestion: printf is filled in with the right % code for your variable type. Inside a string, type % to get the matching format code. Press Ctrl+Space to show suggestions anywhere.
Terminal
When the program asks for input, type in the terminal and press Enter.Problems and suggestions
Timetable Builder
One row per line as Day,Time,Subject. The tool writes the C program and shows its output.
Common Errors and Fixes
| Mistake | What you see | Fix |
|---|---|---|
Missing ; | "expected ';'" error | End each statement with a semicolon |
No #include | Warning about implicit declaration of printf | Add the include at the top |
Printf or PRINTF | Undefined reference or implicit declaration | C is case sensitive: use printf |
| Missing closing quote | "missing terminating" error | Close every string with " |
Forgot \n | Output runs together on one line | Add \n at the end of the text |
| Wrong file saved | "No such file" | Run the command in the folder containing the .c file |
Resources, Tools and Installation Links
Links open in a new tab. Official sites are listed first for installation.