How qsort Works in C — Sorting Any Type with Function Pointers
Learn how to use qsort in C to sort integers, strings, structs, and custom types. Understand the comparator contract and common mistakes.
Read articleTutorials, tips and guides for C programmers — from beginner mistakes to advanced systems programming.
Learn how to use qsort in C to sort integers, strings, structs, and custom types. Understand the comparator contract and common mistakes.
Read articleLearn how C enums work, their size and underlying type, how to use them as flags, and the common pitfalls around assignment, comparison, and switch statements.
Read articleLearn where to place const in C declarations, the difference between const pointer and pointer to const, and how const correctness prevents bugs at compile time.
Read articleLearn when recursion causes stack overflow in C, how to calculate stack depth limits, tail recursion, and when iteration is a better choice.
Read articleLearn how to measure elapsed time in C using clock(), time(), clock_gettime(), and how to benchmark your code correctly across different platforms.
Read articleLearn how argc and argv work in C, how to parse flags and values, common pitfalls with string conversion, and how to validate arguments correctly.
Read articleLearn when to use volatile in C for memory-mapped hardware, signal handlers, and setjmp. Understand what volatile does and does not guarantee.
Read articleLearn how C unions store multiple types in the same memory. Understand type punning, tagged unions, and the safe way to read from a union you wrote to differently.
Read articleLearn why structs in C have unexpected sizes due to padding. Understand alignment requirements, how to minimize padding, and when to use __attribute__((packed)).
Read articleLearn how to write a Makefile for a C project. Understand rules, dependencies, variables, and automatic variables so you only recompile what changed.
Read article