Under the hood

C, Python and programming tools, explained through the errors you run into.

49 articles

CErrors and crashes

Segmentation fault in C: causes and how to find the line

Your C program stops on "Segmentation fault" and says nothing else? The most common causes, and how to find the exact line with gdb or Valgrind.

Errors and crashes

PythonErrors and crashes

Python mutable default arguments: fix the shared list

Does a Python list remember earlier function calls? Trace a mutable default, fix it with None, and decide whether a caller's list should change.

PythonErrors and crashes

Python strip vs removeprefix: stop removing extra letters

Find out why lstrip removes extra letters, choose between strip, removeprefix and removesuffix, and trim tags while preserving their internal spaces.

PythonErrors and crashes

Python int ValueError: convert and validate an integer

Fix invalid literal for int in Python: signs, empty strings, decimals, isdigit pitfalls and bounded ASCII validation without hiding unrelated errors.

PythonErrors and crashes

Python floor division: negative numbers and modulo

Learn why -7 // 3 is -3 in Python, how modulo gets its sign, why int(a / b) can lose precision, and how to wrap list indices with negative positions.

PythonErrors and crashes

Python zip: different lengths and strict=True

See why Python zip drops unmatched items, when strict=True raises ValueError, and how to choose zip_longest or validate pairs before processing them.

PythonErrors and crashes

Python KeyError: missing keys, get() and in

Fix a Python KeyError by inspecting the key you actually look up. Choose required keys, defaults or counters without confusing missing keys, zero and None.

PythonErrors and crashes

Python nested list copy: shallow copy or deepcopy?

Does copying a Python matrix still change the original? Trace shared rows, choose the right copy depth, and test a transformation that leaves its input intact.

PythonErrors and crashes

Python: remove items from a list while iterating

Does your Python loop leave items behind after remove? Trace the indices, filter without changing the input, and decide when to update the list in place.

CErrors and crashes

while (!feof) in C: why the last line repeats

Find out why while (!feof) repeats the last line in C. Trace fgets, fix the loop, and handle empty files, missing final newlines and read errors.

CErrors and crashes

incompatible pointer type in C: fix it

Fix incompatible pointer type in C by comparing the type a function expects with the type you passed, without hiding the problem behind a cast.

CErrors and crashes

fgets after scanf in C: why it skips a line

Does fgets get skipped after scanf? Track the leftover newline in stdin, fix mixed input, and validate a whole number with fgets and strtol.

CErrors and crashes

free(): double free detected in tcache 2 in C

double free detected in tcache 2, free(): invalid pointer, munmap_chunk(): invalid pointer: where these glibc messages come from and how to fix the bad free.

CErrors and crashes

GCC warnings explained: common messages and how to fix them

control reaches end of non-void function, unused variable, makes pointer from integer, format '%d' expects... Common GCC warnings, their cause and their fix.

CErrors and crashes

implicit declaration of function in C: causes and fix

Since GCC 14, calling an undeclared function is an error. Missing include, missing prototype, typo in the name: the cause and the fix for each case.

CErrors and crashes

printf not printing before a crash in C: stdout and fflush

Your printf never shows up before a segfault, or vanishes in a pipe? How the stdout buffer actually behaves, and three ways to force the output.

CErrors and crashes

undefined reference to in C: fixing the linker error

Your code compiles but ld fails: misspelled main, forgotten .c file, missing -lm, wrong -l order, multiple definition. Each case reproduced with GCC and nm.

Memory and pointers

CMemory and pointers

memcmp vs strcmp in C: bytes, strings and lengths

Compare memcmp and strcmp with embedded null bytes, unsigned values and unequal buffer lengths. See why an equal prefix doesn't mean equal data.

CMemory and pointers

memcpy vs memmove in C: overlapping memory explained

Choose memcpy or memmove in C by checking overlap, copy direction and buffer capacity. Follow a text insertion, a byte trace and a practice exercise.

CMemory and pointers

Array vs pointer in C: sizeof, char[] and char *

An array is not a pointer. sizeof, array decay, a[i] and *(a + i), char[] vs char *, 2D arrays, and the error assignment to expression with array type.

CMemory and pointers

Linked list in C: insert, delete and free without leaks

A complete linked list in C with no leaks: struct node, insert at the head and at the tail, delete one node, free the list, all checked with Valgrind.

CMemory and pointers

malloc, calloc, realloc and free in C: the differences

malloc, calloc, realloc and free: what each one does, the difference between malloc and calloc, and the traps of resizing and freeing memory in C.

CMemory and pointers

Pointers in C explained with memory diagrams

Pointers in C explained with memory diagrams: addresses, & and *, swap, arrays, the NULL pointer, pointers to pointers and function pointers.

CMemory and pointers

Stack vs heap in C: difference, lifetime and size

Stack vs heap in C: how they differ in lifetime, size and speed, where globals and string literals live, and why returning a stack address is a bug.

The C language

PythonThe C language

Python is vs ==: what's the difference?

Equal lists can still be different objects. Choose between is and == in Python, follow aliases, and avoid comparison traps with None, strings and integers.

PythonThe C language

Python range: exclusive stop, negative steps and indices

Use Python range with an exclusive stop, negative steps and empty results. Choose safe bounds for neighboring indices and understand inclusive endpoints.

PythonThe C language

Python Counter: count occurrences and words

Count list occurrences with Python Counter, separate words from characters, and understand result order, ties, missing keys and empty inputs.

PythonThe C language

Python join: convert a list to a string

Turn a Python list into a string with join. Choose separators, fix non-string errors and preserve empty fields with examples and a coding exercise.

PythonThe C language

Python any and all: empty iterables and short-circuiting

Understand Python any and all: truth values, empty iterables, nonempty validation and short-circuiting, with an iterator trace and a practice exercise.

PythonThe C language

Python enumerate: index, value and the start argument

Use Python enumerate to loop over values with their indices, number items from 1, and preserve original positions when slicing or filtering.

PythonThe C language

Python dictionary insertion order, sorting, and equality

Understand Python dictionary order: updating values, deleting and reinserting keys, sorting results, and checking order when dict equality misses the difference.

PythonThe C language

Python split() vs split(" "): whitespace explained

Choose between Python split() and split with a space: repeated whitespace, tabs, empty fields and maxsplit, with runnable examples and a practice exercise.

PythonThe C language

Python sort by multiple keys: tuples and reverse

Sort a Python list by multiple keys: see tuple priority, mixed ascending and descending order, stable ties and the difference between sorted and sort.

CThe C language

Recursion in C: trace calls, returns and local variables

Trace a recursive C function step by step: printf order, separate copies of n, the base case, and why n - 1 and --n produce different return output.

CThe C language

Binary search in C: first occurrence and bounds

Write binary search in C with half-open bounds, follow each step, and handle duplicate values, an empty array and a missing target safely.

CThe C language

argc and argv in C: read arguments safely

Understand argc and argv in C, valid indexes, argv[argc] as NULL, and the check to make before reading a command-line argument.

CThe C language

qsort in C: comparison function without overflow

How to write a qsort comparison function in C: cast void pointers, return the sign, avoid a - b, and sort from INT_MIN to INT_MAX.

CThe C language

GCC 15 defaults to C23: what breaks and how to fix it

GCC 15 compiles C as C23 by default: typedef int bool, f() declarations and parameterless function pointers now fail. The exact errors and how to fix each.

CThe C language

C23 new features: nullptr, constexpr, #embed by example

nullptr, constexpr, typeof, auto, #embed, ckd_add, <stdbit.h>, %b: each C23 feature with an example compiled by GCC 15 and the version that first supports it.

CThe C language

Strings in C: '\0', strlen, strcpy vs strncpy, strcmp

A C string is a char array terminated by '\0'. What that changes for strlen, strcpy, strncpy, strcmp, strdup and fgets, with the warnings GCC 15 prints.

CThe C language

Undefined behavior in C: works on my machine, not on yours

Undefined behavior in C, with examples whose output changes between -O0 and -O2, and how to catch it with -fsanitize=undefined, Valgrind and GCC warnings.

Tools and terminal

Learning to code

Now write it yourself.