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
- Type your program in the C code editor, or click an Example such as Sum of two numbers or Array.
- If the program uses
scanf, type the input values in the Input (stdin) box, for example5 7. - Press Run or Ctrl + Enter.
- Read the result in Output. Below it you see the exit code, or an error message with the line number.
- 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.
scanfthen 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,%cor%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
staticvariable inside a function is reset on every call, so a call counter always shows 1. longis 4 bytes andfloatis stored as adouble, soprintf("%.10f", 1.1f)shows1.1000000000(gcc shows1.1000000238).- Rounding an exact half can differ:
printf("%.1f", 2.25)shows2.3here and2.2with 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:
- C programs for beginners with output
- Prime number program in C and palindrome number program in C
- Factorial program in C using recursion
- Sum of array elements and largest element in an array
- Loop programs in C and the half pyramid pattern
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
printfinside the loop to print the variables on every step, for exampleprintf("i=%d sum=%d\n", i, sum);. Watching the values change shows you exactly where the logic goes wrong.
