All cheatsheets

Cheatsheets

C

Types, pointers & memory, control flow, the preprocessor, and bit operations.

Visualize

C — the call stack & the heap (3D)

Step through a program: stack frames push/pop while a malloc'd heap block outlives its function — then dangles after free().

Loading 3D…

CPU cache — the memory hierarchy (3D)

Each level down is ~10× slower but bigger; caches exploit temporal & spatial locality, so a repeat access is fast.

Loading 3D…

25 entries

Types & declarations7

int / char / float / double

Basic types

uint8_t / int32_t (stdint.h)

Fixed-width integers (embedded)

const / static / extern

Read-only / file-scope / external linkage

volatile

Tell the compiler a value can change outside this code path.

struct Point { int x, y; };

Aggregate type

typedef struct {...} Foo;

Alias a type

enum { LOW, HIGH };

Enumerated constants

Pointers & memory6

int *p = &x;

Pointer holds an address; *p reads/writes the target.

arr[i] == *(arr + i)

Array/pointer duality

malloc / calloc / free

Heap allocation — every malloc needs exactly one free.

p->field

Member via pointer (= (*p).field)

void *

Generic pointer

sizeof(x)

Size in bytes (compile-time)

Control & functions5

if / else / switch

Branching

for / while / do-while

Loops

int add(int a, int b) { return a + b; }

Function definition

static inline

Internal, inlined helper

return / break / continue

Flow control

Preprocessor & bit ops7

#include <stdio.h>

Include a header

#define PIN 5

Macro constant

#ifdef / #ifndef / #endif

Conditional compilation (include guards)

x |= (1 << n)

Recipe: set / clear / toggle / read a register bit.

x &= ~(1 << n)

Clear bit n

x ^= (1 << n)

Toggle bit n

(x >> n) & 1

Read bit n