Skip to content
Devtoolry

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

  1. Write or paste a C program with a main() function.
  2. Put any input your program reads (scanf, fgets) in the stdin box.
  3. Click Run. The first run downloads the compiler (about 23 MB); later runs reuse it.
  4. Read compiler warnings and errors, then the program output and exit code.

Examples

Read a name and a number with scanf

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.

Read numbers until the input ends

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.

Reverse an array with pointers

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.

Structs and formatted output (a marks report)

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

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