Pointer Dereference in C – What *p Actually Prints

What does *p print when p holds the address of a variable? This is the first thing to get straight about pointers, and it’s exactly what this question from our C Programming Quiz App tests. The dereference operator * follows the pointer to its target and reads the value stored there — not the address, …

1 << 31 in C – Signed Overflow Is Undefined Behavior

1 << 31 looks like the obvious way to set the top bit of a 32-bit integer — and it’s signed integer overflow, which C defines as undefined behavior. The scariest part, and the reason this question from our C Programming Quiz App earns its “Hard” rating: unlike most UB in this series, the compiler …

Function Argument Evaluation Order in C – x, x++ Is Undefined

In what order does C evaluate function arguments? The honest answer: whatever order the compiler likes — the standard leaves argument evaluation order unspecified. That alone is survivable. But combine it with a side effect, as in printf(“%d %d”, x, x++), and you cross into undefined behavior. We ran this exact code — from two …

Returning a Pointer to a Local Variable in C – Why It Crashes

Returning a pointer to a local variable is a classic C mistake: the function returns the address of something that stops existing the moment the function returns. The result is a dangling pointer into a dead stack frame — and dereferencing it is undefined behavior. This question from our C Programming Quiz App looks innocent, …

Use After Free in C – Why Reading Freed Memory Is Undefined

Use after free is one of the most dangerous bugs in C: you free() a block of heap memory, then read or write through the pointer anyway. Sometimes the old value is still there and the code “works” — which is precisely what makes this bug so treacherous. It’s undefined behavior, a frequent source of …