Recursive Factorial in C – How fact(5) Unwinds to 120

A function that calls itself, a one-line ternary, and five stack frames deep of multiplication — recursive factorial is the “hello world” of recursion, and this question from our C Programming Quiz App checks that you can actually trace it, because every wrong option is a factorial of something — just not the right thing. …

Pass by Value in C – Why inc(n) Doesn’t Change n

You call inc(n). The function clearly increments its argument. So why is n unchanged afterwards? This question from our C Programming Quiz App tests the single most important fact about C function calls: C passes everything by value — and a function that forgets this compiles cleanly, runs happily, and does nothing. The Quiz Question …

Function Call and Return in C – How add(3, 4) Becomes 7

add(3, 4) — the simplest function call in C. Too simple to get wrong? The wrong options in this question from our C Programming Quiz App each encode a real beginner misconception about what a function call is: how arguments travel in, and how the result travels back. The Quiz Question int add(int a, int …

Static Local Variables in C – Why the Counter Prints 1 2 3

Call the same function three times and it prints three different numbers — from a variable that’s initialized to zero right there in the function body. This question from our C Programming Quiz App is the classic test of the static keyword’s second job: giving a local variable a memory that outlives the call. The …

sizeof vs strlen in C – Why sizeof(s) – strlen(s) Is 1

Two ways to measure one string, subtracted from each other. sizeof and strlen are the most-confused pair in beginner C, and this question from our C Programming Quiz App weaponizes the confusion: if you know exactly what each one counts, the subtraction is trivial — and if you don’t, every wrong option looks plausible. The …