C Get Started
To get started with C you need two things: a text editor to write your code and a compiler to turn that code into a program your computer can run. C is a compiled language, which means the source code is translated into machine code before it runs.
Installing a C Compiler
- Windows: install MSYS2 and run "pacman -S mingw-w64-ucrt-x86_64-gcc", or install Visual Studio with the "Desktop development with C++" workload (it includes a C compiler).
- macOS: run "xcode-select --install" in Terminal to get Clang.
- Linux: run "sudo apt install build-essential" (Debian/Ubuntu) or "sudo dnf install gcc" (Fedora).
- Check it works by running "gcc --version" or "clang --version".
Writing and Compiling a C Program
Create a file called hello.c and type the program below. C source files always use the .c extension.
#include <stdio.h>
int main(void) {
printf("C is up and running!\n");
return 0;
}C is up and running!
Open a terminal in the same folder and compile it:
gcc -std=c17 -Wall -Wextra hello.c -o hello
Then run the program with ./hello on macOS/Linux or hello.exe on Windows. The -Wall and -Wextra flags turn on helpful warnings, and -o hello names the output file.
What the Compiler Does
- Preprocessing: lines starting with # (like #include) are processed first.
- Compiling: your C code is translated into assembly and then machine code.
- Linking: your code is joined with library code (such as printf) into one executable.
Using an IDE
You can also use an editor such as Visual Studio Code with the C/C++ extension, CLion, or Code::Blocks. They give you syntax highlighting, error hints and a run button, but it is still worth knowing the command line because it shows exactly what happens.
Frequently asked questions
What is the best C compiler for beginners?
GCC and Clang are both free, standard-compliant and widely used. On Windows, GCC through MSYS2 or the MSVC compiler from Visual Studio are both good choices.
How do I run a C program in VS Code?
Install a compiler such as GCC, then install the Microsoft C/C++ extension. Open your .c file and use the Run or Debug button, or compile in the integrated terminal with gcc.
What does gcc -o mean?
The -o option sets the name of the output file. Without it, GCC names the program a.out on Linux/macOS or a.exe on Windows.