Think you have what it takes to tackle the most common low-level bugs in programming? Put your skills to the test with our challenging quiz and see if you can debug these tricky scenarios.
1. What kind of error does the following code produce?
print('hello'
Missing parentheses
Arithmetic Error
Logic Error
Syntax Error: Unclosed string literal
2. Given this code, what kind of bug is present?
int arr[5];
arr[5] = 1;
Accessing memory outside the bounds of the array
Division by zero error
Memory leak
Using uninitialized memory
3. Why might the following code fail at runtime?
int a = 5 / 0;
Buffer Overflow
Syntax Error
Null Pointer Dereference
Arithmetic Error: Division by Zero
4. Identify the bug in this code (common in C):
if(file = fopen('text.txt', 'r'))
Off-by-one error
Assignment instead of Comparison
Incorrect conditional syntax
Using bitwise instead of logical operator
5. What could cause the following code to use excessive resources?
while(true) {}
Memory Leak
Uninitialized Variable
Infinite Loop
Double Freeing Memory
6. Why might the following code cause an issue?
char* ptr = (char*)malloc(10);
Using Uninitialized Memory
Off-by-One Error
Not Checking for NULL Return Value
Double Freeing Memory
7. Given this function, what is the potential issue?
void func(char* s) {s[10] = 'a';}
Writing past the allocated memory boundaries
Double Freeing Memory
Memory Leak
Off-by-One Error
8. What's the issue with the following C code?
int* ptr;
printf('%d', *ptr);
Accessing Freed Memory
Dereferencing an Invalid Memory Address
Incorrect Format String
Uninitialized Variable
9. Identify the bug in this code:
int* p = NULL;
*p = 10;
Accessing Freed Memory
Dereferencing Null Pointer
Buffer Overflow
Integer Overflow
10. Why would the following program crash?
char str[5] = 'hello';
Buffer Overflow
Array Initialization Error
Incorrect Array Declaration
Memory Leak
11. What type of error is introduced here?
int* p;
for(int i = 0; i < 10; i++) p[i] = i;
Buffer Overflow
Accessing Invalid Memory
Using Uninitialized Pointer
Double Freeing Memory
12. What's the potential issue with this code?
FILE* f = fopen('data.txt', 'r');