0 day streak
Code library

Code worth reading.

Hand-picked snippets across TypeScript, Python, Rust, Go, and more — each one comes with a line-by-line breakdown so you can read it like the people who wrote it.

3495 snippets · 10 languages
▶ Start learning
C · BeginnerSnippet

Variable Data Types

In C, you must declare the type of data a variable will hold, such as integers (int), floating-point numbers (float), or single characters (char).

snippet.c
c
1
2
3
int age = 25;
float temperature = 36.5;
char grade = 'A';
Data TypesSyntax
C · BeginnerSnippet

If-Else Control Flow

Conditional statements allow the program to make decisions and execute different blocks of code based on a boolean expression.

snippet.c
c
1
2
3
4
5
6
7
int score = 85;
if (score >= 50) {
printf("Pass\n");
} else {
printf("Fail\n");
}
Control Flow
C · BeginnerSnippet

Hello World Basics

This is the simplest C program. It includes the standard input-output library and defines the main entry point where execution begins.

snippet.c
c
1
2
3
4
5
6
#include <stdio.h>
int main() {
printf("Hello, World!\n");
return 0;
}
SyntaxFunctions
C · BeginnerSnippet

Simple For Loop

A for loop repeats a block of code a specific number of times, using a counter variable to track progress.

snippet.c
c
1
2
3
for (int i = 0; i < 5; i++) {
printf("Iteration: %d\n", i);
}
Control FlowSyntax
C · BeginnerSnippet

Function Definition

Functions are reusable blocks of code that perform specific tasks. They can take parameters and return a value.

snippet.c
c
1
2
3
4
5
int add(int a, int b) {
return a + b;
}
// Usage: int result = add(5, 3);
FunctionsBest Practices
C · BeginnerSnippet

Strings as Character Arrays

In C, strings are simply arrays of characters ending with a special null character '\0'.

snippet.c
c
1
2
char greeting[] = "Hello";
printf("%s has %lu characters", greeting, strlen(greeting));
Arrays & ListsSyntax
C · BeginnerSnippet

Defining a Struct

A struct is a user-defined data type that allows grouping related variables of different types together.

snippet.c
c
1
2
3
4
5
6
struct Player {
int id;
float health;
};
struct Player p1 = {1, 100.0};
SyntaxData Types
C · BeginnerSnippet

The Switch Statement

The switch statement is an alternative to long if-else chains. It compares a variable against multiple 'case' values and executes the matching block.

snippet.c
c
1
2
3
4
5
6
7
8
9
10
switch (grade) {
case 'A':
printf("Excellent!\n");
break;
case 'B':
printf("Good job!\n");
break;
default:
printf("Keep trying.\n");
}
Control FlowSyntax