Back to home
c programming language icon

C Online Compiler

Practice C right here — no installs, no signups.

C Compiler
Output
Code runs on the Play with Coding execution engine — your code is saved locally for next time.

About the C online compiler

C is the language operating systems, embedded firmware and every other language's runtime are written in. Learning it teaches you what a pointer actually is and where memory comes from. This online C compiler compiles and links your program, then prints the program output and any compiler diagnostics.

Use it to practise pointers and arrays, structs, dynamic allocation with malloc/free, string handling with the standard library, and file-free input via scanf. Compiler warnings are shown too — reading them is half of learning C.

  • First-year engineering C practicals
  • Understanding pointer arithmetic hands on
  • Practising structs and dynamic memory
  • Testing printf format specifiers

C sample programs you can run right now

Copy any snippet into the editor above and press Run. Each one is short on purpose — retype it from memory afterwards.

Pointers and arrays

#include <stdio.h>

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

An array name decays to a pointer to its first element, so *(p + i) is exactly nums[i].

Structs

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

struct Student { char name[20]; int marks; };

int main(void) {
  struct Student s;
  strcpy(s.name, "Aarav");
  s.marks = 78;
  printf("%s scored %d\n", s.name, s.marks);
  return 0;
}

Strings in C are char arrays — you copy them with strcpy, not with =.

Common C errors and how to fix them

warning: implicit declaration of function 'printf'

Why: The header that declares the function was not included.

Fix: Add #include <stdio.h> at the top.

Segmentation fault

Why: You dereferenced an invalid or freed pointer, or wrote past the end of an array.

Fix: Check array bounds and confirm every pointer is assigned before use.

error: expected ';' before '}' token

Why: A missing semicolon on the previous statement.

Fix: C needs a semicolon after every statement — look at the line above the reported one.

C syntax cheatsheet

ConceptSyntax
Entry pointint main(void) { return 0; }
Print an intprintf("%d\n", x);
Read an intscanf("%d", &x);
Pointerint *p = &x;
Allocateint *a = malloc(n * sizeof(int));
Structstruct P { int x; };

C compiler FAQs

Which C standard is used?

A modern C compiler is used, so C99/C11 features such as declaring loop variables inside for work.

Why does my program print nothing?

Either you never called printf, or the program crashed before reaching it — check the diagnostics panel for a segmentation fault.

Keep going after the compiler

Running snippets builds speed; the 17-chapter course builds understanding. Work through the C chapters, take the quiz, then claim your certificate.

Other compilers: JavaScript compiler, TypeScript compiler, Python 3 compiler, Java compiler, C++ compiler, Go compiler, Rust compiler, HTML compiler, CSS compiler, SQLite compiler