C · Playground

C playground

Running C inside the browser is not available yet. Use this editor to write, then download the file and run it locally with GCC 13 (C11). The example snippets were verified that way.

#include <stdio.h>

int main(void)
{
    printf("Ferry timetable\n");
    printf("Harbour -> Island: ");
    printf("07:30\n");
    printf("Island -> Harbour: 18:15\n");
    return 0;
}

Output

Press Run to see the program’s output here.

Running C inside the browser is not available yet. Use this editor to write, then download the file and run it locally with GCC 13 (C11). The example snippets were verified that way.

C examples

Each one was run with GCC 13 (C11) before it was published. Load one, change it, run it.

  •  C · C Syntax and Your First Program: Printing several lines
    #include <stdio.h>
    
    int main(void)
    {
        printf("Ferry timetable\n");
        printf("Harbour -> Island: ");
        printf("07:30\n");
        printf("Island -> Harbour: 18:15\n");
        return 0;
    }
    
  •  C · C Syntax and Your First Program: Layout is free, punctuation is not
    #include <stdio.h>
    int main(void){int a=4;int b=9;
    printf("%d + %d = %d\n",
           a, b,
           a + b);return 0;}
    
  •  C · Variables and Types in C: Declaring, printing and measuring
    #include <stdio.h>
    #include <stdbool.h>
    
    int main(void)
    {
        int shelves = 12;
        long books = 48250L;
        double avg_weight = 0.85;
        char section = 'H';
        bool open_today = true;
    
        printf("Shelves: %d\n", shelves);
        printf("Books: %ld\n", books);
        printf("Average weight: %.2f kg\n", avg_weight);
        printf("Section: %c\n", section);
        printf("Open today: %d\n", open_today);
        printf("sizeof(int) = %zu, sizeof(double) = %zu\n", sizeof(int), sizeof(double));
        return 0;
    }
    
  •  C · Variables and Types in C: Values change, types do not
    #include <stdio.h>
    
    int main(void)
    {
        int stock = 40;
        printf("Start: %d\n", stock);
        stock = stock - 15;
        printf("After sale: %d\n", stock);
        stock = 7.9;          /* the fraction is thrown away */
        printf("Assigned 7.9: %d\n", stock);
        const int capacity = 100;
        printf("Capacity: %d\n", capacity);
        return 0;
    }
    
  •  C · Operators in C: Integer division and remainder
    #include <stdio.h>
    
    int main(void)
    {
        int departure = 517;              /* minutes after midnight */
        int hours = departure / 60;
        int minutes = departure % 60;
        printf("Departure: %02d:%02d\n", hours, minutes);
    
        int seats = 45, passengers = 32;
        printf("Occupancy (int): %d\n", passengers * 100 / seats);
        printf("Occupancy (double): %.1f%%\n", (double) passengers * 100 / seats);
        printf("-7 / 2 = %d, -7 %% 2 = %d\n", -7 / 2, -7 % 2);
        return 0;
    }
    

How this page was checked. Every program on it was run with GCC 13 (C11) at build time by the publishing checks, and the output shown is what it printed. Running C inside the browser is not available yet, so the Run button is absent rather than pretending; copy the code and run it with GCC 13 (C11) locally.