Kodewick
Start learning →

Online C Compiler

Free, no gcc to install, no sign-in. Run it, then watch every pointer and malloc’d block, step by step.

Try:
Online C CompilerFull screen · your code and output are still here
C
Examples
swap.c
#include <stdio.h>

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

int main(void) {
    int x = 3, y = 5;
    swap(&x, &y);
    printf("%d %d\n", x, y);
    return 0;
}
Output

Press Run to see the result

gcc 13 · C11Ln 1, Col 1Spaces: 4Learn C →Change it to keep it in My code
Not just run

Watch your C run: the stack, the heap, every pointer

Each variable sits in its function’s frame on the stack; malloc’d blocks sit on the heap; a pointer is an arrow. A freed block turns grey, a lost one red.

▶ Plays right here, no sign-in
Debug & share

Run it, pause it, replay it, share it

As handy as VS Code on your computer, plus what it does not have: every step drawn.

Step

One line at a time, every value beside it

Press Step and the code stops at each line: the lit line runs next, and every variable’s value sits beside it. Go back too, with the ← → keys.

One line at a time, every value beside it
Replay an error

It crashed? See exactly how it went wrong

Under the error, press “See how it went wrong”: the visualizer opens at the failing step, in red, with the reason in plain words. Step back through everything before it.

It crashed? See exactly how it went wrong
Share

A link, a GIF, a picture of the code: post it to X

A link opens this very code. Or export a GIF of it running (light or dark, wide or tall) or a picture of the code, and post it to X, a chat, or embed it in a blog.

A link, a GIF, a picture of the code: post it to X
Examples

12 C examples: one click runs them above

Each one can be stepped through and visualized. Change it, run it again.

Reading input with scanf

scanf waits for two numbers; type them in the output panel.

#include <stdio.h>

int main(void) {
    int a, b;
    scanf("%d %d", &a, &b);
    printf("%d + %d = %d\n", a, b, a + b);
    return 0;
}

Swap with pointers

The classic: why swap needs &x and &y.

#include <stdio.h>

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

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

Arrays and pointers

a[i] and *(p + i) are the same element.

#include <stdio.h>

int main(void) {
    int a[4] = {10, 20, 30, 40};
    int *p = a;
    for (int i = 0; i < 4; i++)
        printf("%d %d\n", a[i], *(p + i));
    return 0;
}

Reverse a string

A char array, strlen, two ends swapping inwards.

#include <stdio.h>
#include <string.h>

int main(void) {
    char s[20] = "hello";
    int n = strlen(s);
    for (int i = 0; i < n / 2; i++) {
        char t = s[i];
        s[i] = s[n - 1 - i];
        s[n - 1 - i] = t;
    }
    printf("%s\n", s);
    return 0;
}

A dynamic array with malloc

Ask for n ints on the heap, use them, free them.

#include <stdio.h>
#include <stdlib.h>

int main(void) {
    int n = 5;
    int *sq = malloc(n * sizeof(int));
    for (int i = 0; i < n; i++)
        sq[i] = i * i;
    for (int i = 0; i < n; i++)
        printf("%d ", sq[i]);
    printf("\n");
    free(sq);
    return 0;
}

An array of structs

Find the best score among students.

#include <stdio.h>

struct Stu {
    char name[10];
    int score;
};

int main(void) {
    struct Stu s[3] = {{"Lin", 88}, {"Zhou", 95}, {"Chen", 79}};
    int best = 0;
    for (int i = 1; i < 3; i++)
        if (s[i].score > s[best].score) best = i;
    printf("%s %d\n", s[best].name, s[best].score);
    return 0;
}

A linked list

Nodes from malloc, linked by pointers, then freed.

#include <stdio.h>
#include <stdlib.h>

struct Node {
    int val;
    struct Node *next;
};

int main(void) {
    struct Node *head = NULL;
    for (int i = 3; i >= 1; i--) {
        struct Node *p = malloc(sizeof(struct Node));
        p->val = i;
        p->next = head;
        head = p;
    }
    for (struct Node *p = head; p != NULL; p = p->next)
        printf("%d ", p->val);
    printf("\n");
    while (head) {
        struct Node *nx = head->next;
        free(head);
        head = nx;
    }
    return 0;
}

A 2D array

A multiplication table, drawn as a grid in the visualizer.

#include <stdio.h>

int main(void) {
    int t[3][4];
    for (int i = 0; i < 3; i++)
        for (int j = 0; j < 4; j++)
            t[i][j] = (i + 1) * (j + 1);
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 4; j++)
            printf("%3d", t[i][j]);
        printf("\n");
    }
    return 0;
}

Recursion: Fibonacci

A function that calls itself: watch the frames stack up.

#include <stdio.h>

int fib(int n) {
    if (n <= 2) return 1;
    return fib(n - 1) + fib(n - 2);
}

int main(void) {
    printf("%d\n", fib(6));
    return 0;
}

Bubble sort

Neighbours swap until the array is in order.

#include <stdio.h>

int main(void) {
    int a[6] = {5, 2, 9, 1, 7, 3};
    int n = 6;
    for (int i = 0; i < n - 1; i++)
        for (int j = 0; j < n - 1 - i; j++)
            if (a[j] > a[j + 1]) {
                int t = a[j];
                a[j] = a[j + 1];
                a[j + 1] = t;
            }
    for (int i = 0; i < n; i++) printf("%d ", a[i]);
    printf("\n");
    return 0;
}

FizzBuzz

A loop, % and if / else if.

#include <stdio.h>

int main(void) {
    for (int i = 1; i <= 15; i++) {
        if (i % 15 == 0) printf("FizzBuzz\n");
        else if (i % 3 == 0) printf("Fizz\n");
        else if (i % 5 == 0) printf("Buzz\n");
        else printf("%d\n", i);
    }
    return 0;
}

Out of bounds

Real gcc runs on quietly; here it stops at the bad read and shows why.

#include <stdio.h>

int main(void) {
    int a[5] = {1, 2, 3, 4, 5};
    int sum = 0;
    for (int i = 0; i <= 5; i++)
        sum += a[i];
    printf("%d\n", sum);
    return 0;
}
Three steps

How to run C online

  1. 1
    Write code, or pick an exampleThe editor works like VS Code: completion, matching brackets, Ctrl+/ to comment.
  2. 2
    Press Run, or Ctrl + EnterThe output shows beside the code; when the program calls scanf(), answer it right there.
  3. 3
    To see how it runs: Step, or VisualizeYour code is kept in this browser; find it again in My code.
What works

C, running in your browser

✓ Works

  • C11: pointers, arrays, structs, unions, enums, function pointers
  • stdio, stdlib, string, math, ctype …
  • scanf / getchar reading from the output panel
  • malloc / free, with leaks and use-after-free shown
  • Compile errors and warnings in gcc’s words

✕ Not yet

  • Threads, sockets, signals, files on your computer
  • Inline assembly and compiler extensions
  • Libraries outside the C standard library
  • Programs that never end (stopped after 30 s)
FAQ

About the online C compiler

Is it free? Do I need an account?

No and no. Open the page and write C; your code stays in your own browser.

Is this real gcc?

It is our own C engine running in your browser, made to give the same output as gcc 13 for C11 programs. Unlike gcc it stops at undefined behaviour, such as reading past an array, and tells you where.

My program uses scanf. Where do I type?

When it reaches scanf, a box appears in the output: type, press Enter, it carries on.

How do I see pointers and memory?

Press Visualize: the stack is on the left, the heap on the right, and every pointer is an arrow. Freed blocks turn grey; leaked ones are red at the end.

My program crashed. Can I see why?

Under the error, press “See how it went wrong”: the visualizer opens at the failing step and you can go back through it.

Does it work on a phone?

Yes. Tap the code to write full screen, with keys for Tab, braces and semicolons.

Where is my code kept?

In this browser, under My code. Share anything important as a link.

How do I share it?

Share → Copy link, or export a GIF of it running, or a picture of the code, and post it to X.

More

Four more languages, the same tools