Online C Compiler
Compile and run C code online with Clang 21, a GCC-compatible compiler: pick C89 (ANSI C), C99, C11, C17 or C23 and add stdin input. Your code stays private.
Runs in your browser · Nothing uploadedFree · No sign-up
Something not working, or missing a feature? Send feedback
About the C Compiler
The online C Compiler builds your C language program with Clang 21, a GCC-compatible compiler, in C17, C23, C11, C99 or C89 (ANSI C) mode. It runs the program straight away with the input you type. Test a function, check pointer arithmetic or practise for an exam or lab without installing GCC, Turbo C or an IDE. If you were searching for a GCC compiler online, this Clang online compiler accepts the same flags and nearly every program GCC does. It works on a phone as well as a laptop, and the compiler runs in your browser as WebAssembly: your code is never uploaded.
Your code runs in an isolated Web Worker in your browser, so it never leaves your device.
How to use the C Compiler
- Write or paste a C program with a main() function.
- Put any input your program reads (scanf, fgets) in the stdin box.
- Click Run. The first run downloads the compiler (about 23 MB); later runs reuse it.
- Read compiler warnings and errors, then the program output and exit code.
Examples
Input
#include <stdio.h>
int main(void) {
char name[32];
int age;
if (scanf("%31s %d", name, &age) != 2) {
printf("Expected a name and an age\n");
return 1;
}
printf("Hi %s, next year you will be %d.\n", name, age + 1);
return 0;
}Result
Hi Priya, next year you will be 22.
With "Priya 21" in the stdin box. %31s stops at the first space and never writes past the 32-byte buffer; checking that scanf returned 2 catches missing input.
Input
#include <stdio.h>
int main(void) {
int n, sum = 0;
while (scanf("%d", &n) == 1) sum += n;
printf("Sum: %d\n", sum);
return 0;
}Result
Sum: 108
With "4 8 15" and "16 23 42" on two stdin lines. scanf returns EOF when the stdin box is used up, which ends the loop.
Input
#include <stdio.h>
void reverse(int *a, int n) {
int *left = a, *right = a + n - 1;
while (left < right) {
int tmp = *left;
*left++ = *right;
*right-- = tmp;
}
}
int main(void) {
int nums[] = {10, 20, 30, 40, 50};
int n = sizeof nums / sizeof nums[0];
reverse(nums, n);
for (int i = 0; i < n; i++) printf("%d ", nums[i]);
printf("\n");
return 0;
}Result
50 40 30 20 10
sizeof nums / sizeof nums[0] only works where nums is a real array; inside reverse() it is a pointer, which is why the length is passed in.
Input
#include <stdio.h>
struct student {
char name[20];
int marks[3];
};
double average(const struct student *s) {
int total = 0;
for (int i = 0; i < 3; i++) total += s->marks[i];
return total / 3.0;
}
int main(void) {
struct student s;
while (scanf("%19s %d %d %d", s.name, &s.marks[0], &s.marks[1], &s.marks[2]) == 4) {
double avg = average(&s);
printf("%-6s %6.2f %s\n", s.name, avg, avg >= 40 ? "PASS" : "FAIL");
}
return 0;
}Result
Asha 84.67 PASS Ravi 35.67 FAIL Meera 65.67 PASS
With "Asha 78 85 91", "Ravi 35 42 30" and "Meera 66 59 72" on three stdin lines. Dividing by 3.0 instead of 3 keeps the decimals; %-6s pads names to line up the columns.
Common mistakes
- Waiting for keyboard input. There is no interactive terminal. Type everything the program reads into the stdin box before you click Run; once it is used up, scanf returns EOF and fgets returns NULL.
- Turbo C headers and gets(). conio.h (clrscr, getch) is a Turbo C and Windows header, so Clang stops with "conio.h file not found"; remove those calls. gets() was removed from C in C11 and is reported as an undeclared function: use fgets(buf, sizeof buf, stdin) instead.
- Null pointers do not always crash. In WebAssembly, address 0 is ordinary memory, so reading through a NULL pointer returns whatever is stored there (often 0) instead of a segmentation fault. A NULL write the optimiser can see ends with "Program aborted.", and running past the end of memory or the stack stops with "Runtime error: memory access out of bounds".
- Assuming 64-bit sizes. The program is compiled for 32-bit WebAssembly, so long and pointers are 4 bytes (sizeof(long) is 4). Use long long or int64_t from <stdint.h> when you need 64-bit integers.
- Files, sockets and threads. fopen, socket calls and pthread_create fail in the sandbox. Read data from stdin and keep the program single-threaded.
Works well with the C Compiler
- C++ Compiler: run the same program as C++ with the standard library containers.
- Number Base Converter: check bit masks and hex values your program prints.
- Text & Code Diff: compare the output with the expected answer.
Frequently asked questions
Which C standard and compiler are used?
Clang 21 with -O2 -Wall and C17 by default; choose C23, C11, C99 or C89 (ANSI C) in the menu next to Run. Programs link the WASI C library (a musl-based libc) and the maths library. Code that compiles with GCC in the same mode almost always compiles here too.
Why is the first run slower?
The Clang toolchain is downloaded once (about 23 MB compressed) and then cached by your browser. Later runs only compile and execute your code.
Can I use it as an online GCC compiler?
Yes, for almost all programs. It runs Clang, which accepts the same C syntax, the same headers and almost all GCC extensions, so code written for gcc -std=c17 compiles unchanged. Only the wording of some warnings differs, and GCC-only flags are not needed.
Can I compile C23 code?
Yes. Choose C23 in the menu next to Run to use bool, true and false without a header, nullptr, constexpr, typeof, binary literals such as 0b101 and the other C23 additions. In the default C17 mode those are errors, as they would be with gcc -std=c17.
Is there an ANSI C (C89) mode?
Yes. Choose C89 (ANSI C) to compile as -std=c89, the standard used by many textbooks and Turbo C era courses. Clang reports C99 features such as // comments or a variable declared inside for ( ) as warnings, so read the warnings to see what an older compiler would reject.
How do I give input to my C program?
Type it into the "Standard input (stdin)" box before you click Run, one value per line or separated by spaces, exactly as you would type it in a terminal. scanf, getchar and fgets read from that box in order.
Is there a terminal like in Turbo C or Code::Blocks?
The output panel works like a terminal window: it shows everything printf writes, compiler errors with line and column, and the exit code. Input is typed in advance in the stdin box instead of while the program runs.
Which header files can I use?
The standard C library: stdio.h, stdlib.h, string.h, math.h, ctype.h, stdbool.h, stdint.h, inttypes.h, limits.h, float.h, time.h, assert.h and errno.h, plus POSIX unistd.h (sleep works). Platform headers such as conio.h, windows.h and graphics.h are not available.
Does the online C compiler work on mobile?
Yes. It runs in any modern mobile browser on Android or iPhone. The editor and the output stack vertically on small screens, and after the first run the compiler stays cached on the phone.
How long can my program run?
Up to 5 seconds per run on the free plan and 15 seconds on Pro. Compilation does not count. A program that runs longer, such as an infinite loop, is stopped and marked "Timed out", and you can run again straight away.
Is it free, and do I need an account?
It is free and needs no sign-up. Open the page, write your code and click Run.
Is my code sent to a server?
No. Both the compiler and your program run in your browser as WebAssembly, so the code and its input stay on your device.
Does it work offline?
After the first run the compiler is in your browser cache, so later runs work even on a slow connection. The page itself still needs to load.
What do "implicit declaration" and "undefined reference" mean?
An implicit declaration means you called a function before declaring it, usually a missing #include. An undefined reference is a linker error: the function was declared but never defined. Both are explained with real compiler output in our C compiler errors guide.
What is the difference between GCC and Clang?
Both compile the same C language and accept the same everyday flags. Clang usually words errors more directly, and GCC supports a few extensions Clang does not, such as nested functions. Our GCC vs Clang guide compares them with real output.
How do I take a string with spaces as input in C?
Type the line into the stdin box and read it with fgets(buf, sizeof buf, stdin), then remove the trailing newline. scanf("%s") stops at the first space. The strings in C guide shows the full pattern.
Which online C compiler is best?
It depends on the job. For stepping through code with breakpoints, a debugger-based site such as OnlineGDB fits; for reading the generated assembly, Compiler Explorer. This compiler suits learning, exams and quick tests: it needs no sign-up, keeps your code in your browser, reads stdin input and switches between C89, C99, C11, C17 and C23.
Guides and tutorials
- Programming Languages
-O0 vs -O2 vs -O3: GCC and Clang Optimization Levels Benchmarked
-O2 vs -O3 measured with GCC and Clang on five C programs: when -O3 wins, when it is slower, what -Ofast breaks, plus code size and compile time per -O level.
· 10 min read
- Programming Languages
GCC Command Line Options Explained: -o, -c, -Wall, -std, -O2, -g and -lm
The GCC options you use every day, with real output from GCC 11: naming the output, compiling in steps, warnings, -std, -O levels, -g, -I, -D and -lm.
· 9 min read
- Programming Languages
malloc vs calloc in C: Which Is Faster? We Measured
The difference between malloc and calloc in C, measured: zeroing, speed on fresh and reused memory, overflow checks, and which one to use in your own code.
· 9 min read
- Programming Languages
How to Compile and Run C Code Online (No Install, With Input)
Compile and run C code online in your browser: a first program, reading stdin input, choosing a C standard from C89 to C23, and fixing common errors.
· 4 min read
- Programming Languages
C Compiler Errors and Warnings, Explained With Fixes for Clang and GCC
10 common C compiler errors and warnings, from expected ';' to undefined reference, with real Clang and GCC output, what each one means and how to fix it.
· 7 min read
- Programming Languages
GCC vs Clang: What Is the Difference for C Programmers?
Clang vs GCC benchmarked on five programs: Clang won three, GCC one, one tie. Plus error messages, flags, GNU extensions and which to use for C and C++.
· 12 min read
- Programming Languages
Pointers in C Explained: Addresses, Arrays and Memory with Runnable Examples
Learn C pointers step by step: & and *, double pointers (**), pointers in functions, arrays, pointer arithmetic, malloc and free, and the bugs to avoid.
· 8 min read
- Programming Languages
Strings in C: char Arrays, the Null Terminator and the Bugs to Avoid
Strings in C with tested examples: char arrays and the \0 terminator, strlen vs sizeof, strcmp, strcpy vs snprintf, strtok and reading a string with spaces.
· 9 min read
- Programming Languages
How to Run C++ Code Online: Compile C++20 with Input in Your Browser
Run C++ code online with C++20: compile a first program, feed stdin, use vectors and structured bindings, read g++ errors and avoid the common beginner traps.
· 4 min read
Related tools
JavaScript Compiler
Run JavaScript online in an isolated browser sandbox. See console output, errors and execution time instantly, with top-level await and stdin input.
TypeScript Compiler
Compile and run TypeScript online. Your code is type-checked with the official compiler in strict mode, then runs in a sandboxed worker in your browser.
Python Compiler
Run Python 3 code online with the full standard library and stdin input. It runs in your browser with Pyodide (WebAssembly), so your code stays on your device.
PHP Compiler
Run PHP 8.4 code online and see the output instantly, with stdin input and mbstring. PHP runs in your browser with WebAssembly, so your code stays private.
C++ Compiler
Run C++ code online for free: compile C++20 with Clang 21 and libc++, type stdin input and see the output. It runs in your browser, so your code stays private.
C# Compiler
Run C# code online with Roslyn and .NET 10: C# 14, top-level statements, LINQ, records and Console.ReadLine input, in your browser, so code stays private.