Text & Developer tool

Online C Compiler: Run C Code in Your Browser

Write a C program, press Run and see the output, right in your browser.

  • Instant results
  • Working shown
  • No sign-up
  • Runs in your browser
ToolUpdates as you type
Examples:
Ctrl + Enter runs the program
Output
Press Run to see the output here.

Your code runs only in your browser, in a C interpreter (JSCPP). Nothing is uploaded or saved. It handles beginner programs: printf/scanf, loops, arrays, functions, recursion, pointers and char strings. It does not support struct or malloc, and all input must be typed before you press Run. For full programs, install gcc on your computer. New to C? Learn C step by step.

How it works

This online C compiler runs C programs inside your browser. A Hello World program is already loaded, so press Run to see its output. If your program reads values with scanf, type them in the Input box before you press Run. It is an interpreter for beginner-level C (printf, scanf, loops, arrays, functions, pointers and strings), not the full gcc compiler, so struct, malloc and some library functions do not work.

This online C compiler lets you write a C program and run it without installing anything. A Hello World program is loaded in the editor. Press Run and the output appears in the panel next to it. It is made for beginners: lab programs, homework and the examples in our C programming tutorial.

Be clear about one thing first: this is an interpreter for a beginner-level subset of C, not gcc. Most first-year programs run exactly as they would on your laptop. Larger programs that use struct or malloc need a real compiler.

How to run a C program online

  1. Type your program in the C code editor, or click an Example such as Sum of two numbers or Array.
  2. If the program uses scanf, type the input values in the Input (stdin) box, for example 5 7.
  3. Press Run or Ctrl + Enter.
  4. Read the result in Output. Below it you see the exit code, or an error message with the line number.
  5. Press Stop to end a program early. Any program still running after 5 seconds is stopped for you.

Each run starts fresh. Tab inserts four spaces, and the line numbers help you match error messages to your code.

Your first program: Hello World

#include <stdio.h>

int main() {
    printf("Hello, World!\n");
    return 0;
}

Output:

Hello, World!

Then the tool shows Program finished with exit code 0. Exit code 0 is the value main returned, and it means the program ended normally. If you are not sure what each line does, read install a C compiler and run your first program, which explains every line.

Run C programs that read input

All input is typed in advance. This program reads two numbers with scanf:

#include <stdio.h>

int main() {
    int a, b;
    printf("Enter two numbers: ");
    scanf("%d %d", &a, &b);
    printf("Sum = %d\n", a + b);
    return 0;
}

With 5 7 in the Input box, the output is:

Enter two numbers: Sum = 12

On a real terminal you would type 5 7 after the prompt, so it would show on the screen. Here the input comes from the box, so the prompt and the answer sit on the same line. That is expected.

Common mistake: A common mistake is pressing Run with an empty Input box. scanf then has nothing to read, the variables never get a value, and the tool stops with "A variable was used before it was given a value". Type the input first, one value for every %d, %f, %c or %s.

Reading error messages

There are two kinds of errors. A compile error means the code could not be read at all, so nothing runs. Here the semicolon after int a = 5 is missing:

#include <stdio.h>

int main() {
    int a = 5
    printf("%d\n", a);
    return 0;
}

The tool shows:

Compile error on line 5: Syntax error near "p".
5 |     printf("%d\n", a);
        ^
Check for a missing semicolon (;), bracket or quote on this line or the line above it.

The mistake is on line 4, but the interpreter only notices it when it reaches printf on line 5. gcc does the same thing, so always check the line above too.

A runtime error happens while the program runs. Dividing by zero, using an array index that is too big, or using a name that was never declared stops the program on that line:

What you wrote What the tool says
a / b when b is 0 Division by zero.
a[3] for int a[3] Array index 3 is out of range. The array has 3 elements, so valid indexes are 0 to 2.
printf("%d", total); with no total declared "total" is not declared.
int big = 2147483647; big = big + 1; Integer overflow: the value 2147483648 does not fit in the type.

The last one is a difference from gcc. A real compiler lets an int silently wrap around to a negative number. This interpreter stops and tells you, which is useful while learning.

What works and what does not

We tested this C online editor with the kinds of programs beginners write. Here is the honest list.

Works Does not work
printf with %d %i %u %ld %lld %f %.2f %e %c %s %x %o %% and widths like %5d struct, union, enum and typedef struct
scanf with %d %f %lf %c %s, also inside loops and into &a[i] malloc, calloc, free and exit
if, else, switch, for, while, do while, break, continue goto and labels
Arrays, 2D arrays, char strings, gets, getchar, putchar, puts fgets, sprintf, strstr, strrev, file functions
Functions, prototypes, recursion, static globals, #define constants Pointers to pointers, arrays of char *, function pointers
Pointers to variables and array elements, swap(&x, &y) stdbool.h, limits.h, stdint.h, conio.h
string.h: strlen, strcpy, strcat, strcmp, strncpy EOF and NULL comparisons
math.h: sqrt, pow, fabs, ceil, floor, sin, log; ctype.h; rand A #define macro with arguments that uses another macro

A few results also differ from gcc:

  • A static variable inside a function is reset on every call, so a call counter always shows 1.
  • long is 4 bytes and float is stored as a double, so printf("%.10f", 1.1f) shows 1.1000000000 (gcc shows 1.1000000238).
  • Rounding an exact half can differ: printf("%.1f", 2.25) shows 2.3 here and 2.2 with gcc.
  • The interpreter is slow. A loop of about 100,000 steps takes a few seconds, so big loops hit the 5-second limit.

If your program needs anything from the right-hand column, or you want the exact behaviour you will see in your lab, install a C compiler such as gcc. It takes about ten minutes.

Practise with C programs

The programs in these pages run well here. Paste one in, run it, then change a value and run it again:

To learn the language topic by topic, read data types in C, operators in C, arrays in C and what a pointer is in C. Writing C++ instead? Use the online C++ compiler.

Pro tip: When a program gives the wrong answer, add a printf inside the loop to print the variables on every step, for example printf("i=%d sum=%d\n", i, sum);. Watching the values change shows you exactly where the logic goes wrong.

Frequently asked questions

Is this a real C compiler?
Not exactly. It is JSCPP, a C interpreter written in JavaScript, so your program runs in the browser instead of being compiled by gcc. For beginner programs with printf, scanf, loops, arrays, functions and pointers the output is the same. It does not support struct, union, enum, malloc or goto, and it runs much slower than a compiled program.
How do I give input to scanf?
Type all the values in the Input (stdin) box before you press Run, separated by spaces or new lines. The program reads them in order. The values you type are not echoed in the output, so a prompt and its answer appear on one line, like Enter two numbers: Sum = 12.
Why does my program say Not supported here?
The interpreter has only part of C. struct, union, enum, typedef struct, malloc and free, fgets, goto, stdbool.h and limits.h are the common things that do not work. Install gcc on your computer to run those programs.
Is my code sent to a server?
No. The interpreter is downloaded once and then runs in your browser. Nothing you type is uploaded or saved, so copy your code into a file if you want to keep it.
Why did my program stop after 5 seconds?
A program that runs longer than 5 seconds is stopped so the page does not freeze. Usually a loop never ends, for example while (i < 10) with no i++. The interpreter is also slow: a loop of about 100,000 steps takes a few seconds.

Try another tool

See all free tools
Chat with us