C Get Started
To write and run C on your own computer you need two things: a text editor to write source code, and a compiler to turn that source code into a program your computer can execute. On ExcelTAD you can skip the setup entirely — every example runs in the browser — but it is worth knowing how the real workflow looks.
Installing a compiler
| Operating system | Recommended compiler | How to get it |
|---|---|---|
| Linux | GCC | Usually preinstalled; otherwise sudo apt install build-essential (Debian/Ubuntu) |
| macOS | Clang | Run xcode-select --install in the Terminal |
| Windows | GCC (MinGW-w64) or MSVC | Install MSYS2 and then pacman -S mingw-w64-ucrt-x86_64-gcc, or install Visual Studio with the C++ workload |
Any editor works: VS Code, Vim, Notepad++, CLion, or a full IDE such as Code::Blocks. An IDE bundles the editor, compiler and debugger behind one "Run" button.
Your first file
C source files end in .c. Create a file called hello.c:
#include <stdio.h>
int main(void) {
printf("Hello from my own computer!\n");
return 0;
}Hello from my own computer!
Compiling and running from the terminal
Open a terminal in the folder that contains hello.c and run:
gcc hello.c -o hello # compile hello.c into an executable named "hello"
./hello # run it (on Windows: hello.exe)Hello from my own computer!
The -o hello option names the output file. Without it, GCC writes a file called a.out (or a.exe on Windows).
Useful compiler options:
| Option | Meaning |
|---|---|
-std=c17 |
Use the C17 standard (what this site uses) |
-Wall -Wextra |
Turn on many helpful warnings — always use these while learning |
-g |
Include debugging information for tools like gdb |
-O2 |
Optimise the program for speed |
-lm |
Link the math library (needed for sqrt, pow, … on Linux) |
Tip: Compile with
gcc -std=c17 -Wall -Wextra hello.c -o hello. Warnings often point straight at bugs before you even run the program.
When something goes wrong
If you make a mistake, the compiler prints an error with the file name, line number and column. For example, forgetting a semicolon:
#include <stdio.h>
int main(void) {
printf("Oops\n")
return 0;
}hello.c: In function 'main':
hello.c:4:21: error: expected ';' before 'return'Read the first error message first: later messages are often side effects of the first one. Fix it, recompile, and repeat.
The edit–compile–run cycle
Unlike Python or JavaScript, C has no interpreter. Every time you change the source you must compile again before running. In practice the loop looks like this:
- Edit
hello.c. - Compile:
gcc -Wall hello.c -o hello. - Run:
./hello. - Read the output (or the error), then go back to step 1.
The playgrounds here do steps 2 and 3 for you when you press ▶ Run. Try changing the program below to print your own name, then run it.
#include <stdio.h>
int main(void) {
printf("My name is Ada.\n");
printf("I am learning C.\n");
return 0;
}My name is Ada.
I am learning C.
Note: The online runner has no keyboard input and does not link the math library, so examples in this course never wait for typing and use math functions in a way that works without
-lm. Everything else behaves like a normal GCC installation.
Test yourself
What file extension do C source files normally use?
- .cpp
- .c
- .h
- .exe
What does -o hello do in gcc hello.c -o hello?
- Optimises the program
- Names the output executable
hello - Opens the file
- Prints the output
You changed your source file. What must you do before the new version runs?
- Nothing, it updates automatically
- Recompile it
- Restart the computer
- Rename the file