- Executors
-
Learn
Learn Python Runnable examples, NumPy, pandas, and more Learn AI / Machine LearningNeural networks, ML and LLMs from scratch Learn C & C++ Pointers, memory, STL, and modern C++ Learn C#C# basics, OOP, LINQ, async, and .NET exercises Learn MatplotlibLine, bar, scatter and pie charts with live visualizers Learn RustOwnership, traits, error handling, and threads Learn GoSlices, interfaces, goroutines, and channels Python Algorithms Search, sorting, recursion, and visualizers O(n) C & C++ Algorithms Compare algorithms implemented in C and C++ Coding for Kids Learn to code by playing!
- QuizzesNew
- ChallengesNew
- For TeachersNew
- Updates
- Buy me a coffee
C Buffer Overflows & Bounds Quiz
C does not check array bounds, so one wrong index can corrupt memory or open a security hole. This quiz shows realistic snippets and asks you to spot off-by-one errors, unsafe string calls and sneaky signed/unsigned comparisons, and pick the safe fix.
Sample question
Question 1 of 10What is the bug in this code?
#include <stdio.h>
int main(void) {
int a[5];
for (int i = 0; i <= 5; i++) {
a[i] = i * i;
}
printf("%d\n", a[4]);
return 0;
}
Show the answer
D. i <= 5 writes to a[5], one element past the end A 5-element array has indexes 0 to 4, so the last iteration writes a[5], outside the array. The fix is i < 5; the <= off-by-one is one of the most common overflow causes.
What this quiz covers
- Off-by-one loops and the missing terminator byte
- What undefined behaviour means for an out-of-bounds write
- Unsafe calls:
gets,strcpywithout a size check - Bounded alternatives:
fgets,snprintf, explicit checks - Finding bugs with
-fsanitize=address
Questions people ask
Do I need an account?
No. Anyone can play. Sign in to keep your XP, streak, badges and history.
Can I retake it?
Yes. Your best score is kept, and the questions and answers are shuffled each time.