Advertisement

Online C Compiler

Write, run and test C code online, right in your browser. This free online C compiler needs no installation or signup — just type your code and click Run.

C is a fast, low-level procedural language used for operating systems, embedded devices and performance-critical software — and a classic first language for learning how computers work.

How to use the C compiler

  1. Write or paste your C code in the editor.
  2. If your program reads input, open the I/O tab and type it into the STDIN box (one value per line).
  3. Click Run — the output and any errors appear in the output panel.

Sample: read input in C

#include <stdio.h>

int main() {
    char name[50];
    scanf("%49s", name);
    printf("Hello, %s!\n", name);
    return 0;
}

Paste this into the editor, type your name in the STDIN box and click Run.

More C examples to try

Read numbers with scanf

Reads a count and then that many integers, and prints the largest one. Try STDIN 5 3 9 2 7 4.

#include <stdio.h>

int main() {
    int n, x, max;
    scanf("%d", &n);
    scanf("%d", &max);
    for (int i = 1; i < n; i++) {
        scanf("%d", &x);
        if (x > max) max = x;
    }
    printf("Largest: %d\n", max);
    return 0;
}

Pointers and functions

Swaps two variables by passing their addresses — the classic way to learn pointers.

#include <stdio.h>

void swap(int *a, int *b) {
    int t = *a;
    *a = *b;
    *b = t;
}

int main() {
    int x = 10, y = 20;
    swap(&x, &y);
    printf("x = %d, y = %d\n", x, y);
    return 0;
}

Common C errors and how to fix them

Segmentation fault (core dumped)
Your program accessed memory it should not — usually an array index out of range, an uninitialised pointer, or scanf("%d", x) without the &.
warning: implicit declaration of function 'printf'
Add #include <stdio.h> at the top. Other functions need their own headers, such as string.h or math.h.
undefined reference to 'sqrt'
Math functions need #include <math.h>; on some compilers the math library must also be linked.
Program prints nothing or the wrong numbers
Check that every scanf has matching input in the STDIN box and that the format (%d, %f, %s) matches the variable type.

Frequently asked questions

Is this online C compiler free?

Yes. It is completely free to use, with no signup required to write and run code.

Do I need to install anything?

No. It all works from your web browser, so there is nothing to download or set up — it works on Windows, macOS, Linux, Chromebooks and phones.

How do I give input to my C program?

Before clicking Run, type the input into the STDIN box under the I/O tab, one value per line. Your program reads it as standard input, just like typing in a terminal.

Is this good for learning C?

Yes. It is ideal for practising exercises, testing small programs and trying out ideas from tutorials, because you can run code instantly without configuring an environment.

Other online compilers

Editor powered by OneCompiler.