Online C Compiler

Write, compile and run C programs online with a real Clang compiler that runs inside your browser. Supports stdin, warnings and the C standard library.

C17 (Clang 21, WebAssembly) · Runs in your browser, so your code never reaches our servers.
main.cC
Output

            
Input (stdin), read by scanf / std::cin / getline
Ctrl/⌘ + Enter to run

How to use the online C compiler

  1. Write or paste a C program with a main function into the editor. Reset example restores the starter program.
  2. If the program reads input with scanf, getchar or fgets, type it into the Input (stdin) box below the output before you run.
  3. Press Run or use Ctrl + Enter (⌘ + Enter on a Mac). The code is compiled first and then executed, and both steps report to the Output panel.
  4. Choose a time limit of 5, 15 or 60 seconds. An endless loop is stopped when the limit is reached, and Stop ends a run immediately.

The first run downloads the compiler, about 30 MB. Your browser caches it, and after that a typical program compiles in well under a second. Use Copy or main.c to save your source file, A− and A+ to change the text size, the layout button to place the editor and output side by side or stacked, and Full screen (Ctrl/⌘ + Shift + F, Esc to leave) for more room.

Compilation and execution both happen inside your browser. Your code is never sent to a server. The editor keeps your last program in your browser's local storage, and in no other place.

How it works and what's supported

This is a real compiler, not an interpreter that imitates C. The page runs Clang/LLVM 21, itself compiled to WebAssembly by the YoWASP project. Clang turns main.c into a WebAssembly (WASI) program, which your browser then runs. The compiler flags are:

clang main.c -std=c17 -O2 -Wall -lm -o main.wasm
  • C17 with optimisation (-O2) and the common warnings (-Wall) turned on.
  • The C standard library from wasi-libc: stdio.h, stdlib.h, string.h, ctype.h, stdint.h, time.h and more. The maths library is linked, so sqrt, pow and sin from math.h work without adding -lm yourself.
  • Exact diagnostics: errors and warnings are shown as Clang prints them, with main.c:line:column positions.
  • Exit codes: if main returns a value other than 0, the output ends with Process exited with code N.

Limitations of a browser sandbox:

  • No threads. pthread.h is not available.
  • No sockets or network access, and no fork or exec.
  • No real file system. You cannot open files on your computer, so use stdin or data in the source instead.
  • No graphics or GUI libraries such as SDL, OpenGL or conio.h/graphics.h. The output is plain text.

Common C pitfalls the compiler can help you spot

Check what scanf returns. It returns the number of values it read, not the value itself. If the stdin box is empty or holds text where a number is expected, the variable keeps whatever value it had before, which may be garbage. The starter program shows the safe pattern:

int n;
if (scanf("%d", &n) != 1) {
    fprintf(stderr, "expected a number\n");
    return 1;               /* reported as exit code 1 */
}

Match printf format specifiers to their types. Use %d for int, %ld for long, %lld for long long, %zu for size_t, %f for double and %c for a character. With -Wall, Clang warns about a mismatch such as printing a double with %d, so read the warnings even when the program runs.

Watch for integer overflow. A 32-bit int stops at 2,147,483,647, and signed overflow is undefined behaviour in C. With -O2, the optimiser may assume it never happens, so an overflowing loop can behave strangely instead of simply wrapping. Use long long (or int64_t from stdint.h) for factorials, large sums and products.

long long f = 1;
for (int i = 2; i <= 20; i++) f *= i;
printf("20! = %lld\n", f);   /* 2432902008176640000 */
Tip: A message about an implicit declaration of a function usually means a missing #include, for example stdlib.h for malloc or string.h for strlen.

Frequently asked questions

Which compiler and C standard does this use?

Clang 21 (LLVM) in C17 mode, with -O2 -Wall. Most code written for GCC compiles unchanged, as long as it sticks to standard C and avoids platform-specific headers.

Is my code uploaded anywhere?

No. The compiler itself runs in your browser, so the source code, the compiled program and its output all stay on your device.

How do I give my program input?

Type it into the stdin box before pressing Run. Values can be separated by spaces or new lines, just as when you type them into a terminal. When the input runs out, scanf returns EOF.

Why does my program stop with a time limit message?

It ran longer than the selected limit, which usually points to a loop that never ends. Check the loop condition, or choose 60 s for genuinely long computations.

Can I compile C++ here?

Use the online C++ compiler, which runs the same Clang in C++20 mode. For other languages, see all the online compilers.

Copied to clipboard