Which C compiler do programming competitions use?
A short guide for competitive programming and olympiads. Try the online compiler →
GCC (GNU Compiler Collection)
GCC is the standard C compiler in competitive programming. Most contest judges run it on Linux, so practise with GCC to get the same behaviour as the judge.
Who uses GCC
| Contest / judge | C compiler |
|---|---|
| IOI (International Olympiad in Informatics) | GCC |
| ICPC (International Collegiate Programming Contest) | GCC |
| TOI (Thailand Olympiad in Informatics) | GCC |
| Codeforces | GNU GCC (also offers others) |
| AtCoder | GCC (also offers Clang) |
Exact versions change from year to year. Check each contest's rules page for the current version and flags.
A typical compile command
gcc -std=c11 -O2 -Wall main.c -o main -lm
./main < input.txt
-std=c11: use the C11 standard (some judges usegnu11or newer).-O2: turn on optimisation, as most judges do.-Wall: show warnings. It catches many bugs before you submit.-lm: link the math library (needed forsqrt,powand others).
Installing GCC
Windows: install MSYS2, then in the MSYS2 UCRT64 terminal run:
pacman -S mingw-w64-ucrt-x86_64-gcc
Ubuntu / Debian Linux:
sudo apt install build-essential
macOS: the built-in gcc command is really Clang. To get real GCC, run brew install gcc and use the versioned command it installs (for example gcc-14).
Starter template
#include <stdio.h>
int main(void) {
int n;
long long sum = 0;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
long long x;
scanf("%lld", &x);
sum += x;
}
printf("%lld\n", sum);
return 0;
}
Tips
- Use
scanf/printffor fast input and output. - Use
long longwith%lldwhen values can go past about 2 billion. - GCC has handy built-ins such as
__builtin_popcount(x)(count set bits) and__builtin_clz(x)(count leading zeros). - Other compilers exist (Clang, MSVC), but they can behave differently from the judge. Stick with GCC to avoid surprises.