C playground
Compile and run C in your browser, without installing gcc: several files with their .h, scanf with prepared input, the compile error highlighted on its line and even processes with fork() and threads with pthread, imitated so that you can practise IC2 on your phone. It is the same environment as the IC2 practical mock exam.
How to use it
- Files: one tab per file. + creates a new one; the pencil (or a double click on its name) renames it and the cross deletes it (it asks for a second click). Header files are included with
#include "grades.h", as on your computer. - Run compiles every
.cfile (the one withmainlast) and runs the program. If it does not compile, the error appears in the Console with its file and line, which is highlighted in the editor. - Input: what
scanfandfgetswill read, one line per read, and the console shows what was read as if you had typed it. It is not interactive: type the data before running. - Your code is saved automatically in this browser. Download gives you the open file and .zip all of them, ready to compile with
gccon your Linux. Upload adds your own.c,.hor data files (.txt) that your program can open withfopenoropen. - Share creates a link with your code inside: whoever opens it sees your files exactly as they are. The code travels inside the link itself; nothing is stored on the website.
- Helps turns on or off the suggestions, bracket closing, extra colours and the highlighted error line: without them you work as with gedit in the exam. The expand button (top right) makes the environment fill the window and A− / A+ change the text size.
Processes and threads in the browser
There is no Linux under the browser, so the environment imitates what IC2 uses:
fork()creates a child process with its own memory: if the child changes a variable, the parent does not notice, as on Fedora.getpid(),getppid()(an orphan child gets 1 as its parent),wait,waitpid,exitandWEXITSTATUSwork. The program is always process 4310 and its children, 4311, 4312…sleepandusleepdo not make you really wait (a few seconds at most), but the output comes out in clock order: what the parent prints after itswaitappears after what the child prints before it ends.- Threads (
pthread_create,pthread_join,pthread_exitand mutexes) run one after another, so you will not see a race condition here: for that, your Fedora. Ifmainends withoutpthread_join, the environment tells you the threads never got to run. - There is no
exec, no pipes, no signals and nopsorpstree: those screenshots, on your Linux.
Paste this into the playground and run it:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>
int main() {
int x = 10;
pid_t pid = fork();
if (pid == 0) {
x = 99; // only the child's x changes
printf("Child %d (parent %d): x = %d\n", getpid(), getppid(), x);
sleep(2);
exit(3);
}
int status;
wait(&status);
printf("Parent %d: my child returned %d and my x is still %d\n", getpid(), WEXITSTATUS(status), x);
return 0;
}
What you can and cannot do
- It compiles with xcc, a C compiler written for WebAssembly (open source, MIT licence), with its standard library:
stdio.h,stdlib.h,string.h,math.h,ctype.h, files withfopenand withopen/read/write,mallocandfree. - It is stricter than
gccin a few things: ascanf("%d", x)without&does not compile (in gcc it is only a warning, and then the program breaks). - It warns about the errors that would be a
Segmentation faulton Fedora: an index outside an array, aNULLpointer or a recursion that never ends, with its line. - Each run can last at most 15 seconds: an infinite loop stops by itself, and you also have the Stop button.
- The first time it downloads the compiler (half a megabyte); after that it starts at once.
Practise with it
- The exercises with solutions of C in IC2: copy the statement, program it here and compare with the solution.
- The IC2 practical mock exam, with this same environment in the programming exercises.
- If you are also learning Python or Java, there is the Python playground and the Java one, and more will arrive in Playgrounds.

What is an operating system — theory with your laptop on a study afternoon, a write() call and a CPU that never rests (and the three programs that weren’t running at the same time)