Back to home
C programming language logo

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

C tutorial: five steps from blank editor to working program

C teaches you what the machine actually does. These steps cover printf and scanf, types, loops, functions, arrays, strings and your first pointers.

  1. 1. main, includes and printf

    Every C program starts at main and returns an int status. printf needs a format specifier for each value: %d for int, %f for float, %s for a string, %c for a char.

    #include <stdio.h>
    
    int main(void) {
        int marks = 87;
        printf("Marks: %d\n", marks);
        return 0;
    }
  2. 2. Read input with scanf

    scanf needs the address of the variable, hence the &. Type your input into the Input (stdin) box before pressing Run.

    #include <stdio.h>
    
    int main(void) {
        int n;
        scanf("%d", &n);
        printf("You typed %d\n", n);
        return 0;
    }
  3. 3. Loops and functions

    Declare a function above main (or prototype it) so the compiler knows its signature before the call.

    #include <stdio.h>
    
    int square(int n) { return n * n; }
    
    int main(void) {
        for (int i = 1; i <= 5; i++) printf("%d ", square(i));
        printf("\n");
        return 0;
    }
  4. 4. Arrays and strings are the same idea

    A C string is just a char array ending with a '\0' byte. That is why sizeof and strlen give different numbers.

    #include <stdio.h>
    #include <string.h>
    
    int main(void) {
        char name[] = "coding";
        printf("%lu %lu\n", sizeof(name), strlen(name));
        return 0;
    }
  5. 5. Pointers, carefully

    A pointer stores an address. * declares one and also reads through it; & takes the address of a variable. Pointers are how C passes data to a function without copying it.

    #include <stdio.h>
    
    void twice(int *n) { *n = *n * 2; }
    
    int main(void) {
        int v = 21;
        twice(&v);
        printf("%d\n", v);
        return 0;
    }

Practice exercises with solutions

Try each one in the editor above before opening the solution — the struggle is where the learning happens.

Beginner

Print a right-angled triangle of stars with 5 rows.

Hint: One loop for rows, a nested loop for the stars in each row.

Show solution
#include <stdio.h>

int main(void) {
    for (int i = 1; i <= 5; i++) {
        for (int j = 0; j < i; j++) printf("*");
        printf("\n");
    }
    return 0;
}
Intermediate

Find the largest element in an array of 6 integers.

Hint: Start max at the first element, not at 0 — negatives matter.

Show solution
#include <stdio.h>

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

Reverse a string in place using two pointers.

Hint: Swap the characters at the ends and move both indexes inward.

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

int main(void) {
    char s[] = "compiler";
    int i = 0, j = strlen(s) - 1;
    while (i < j) {
        char t = s[i]; s[i] = s[j]; s[j] = t;
        i++; j--;
    }
    printf("%s\n", s);
    return 0;
}

Why learn C?

C makes memory, pointers and the cost of an operation visible, which is why it is the standard first language in computer-science courses.

Operating systems, databases and embedded firmware are still written in C, so its concepts show up under almost every other language you learn later.

What C is used for

  • Operating systems, drivers and embedded devices
  • University data-structures coursework
  • Performance-critical libraries other languages call into
  • Competitive programming where speed matters

Ready for structured practice? The 17-chapter C course takes these ideas one at a time, with a quiz and a certificate at the end.