C Quiz: Buffer Overflows & Bounds

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.

कठिन 10 सवाल ~8 मिनट पास होने के लिए 80% C17

मोड चुनें

आप गेस्ट के तौर पर खेल रहे हैं: XP और streak सेव रखने के लिए साइन इन करें।

सैंपल सवाल

सवाल 1 / 10

What 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;
}
जवाब दिखाएं

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.

इस क्विज़ में क्या है

  • Off-by-one loops and the missing terminator byte
  • What undefined behaviour means for an out-of-bounds write
  • Unsafe calls: gets, strcpy without a size check
  • Bounded alternatives: fgets, snprintf, explicit checks
  • Finding bugs with -fsanitize=address

अक्सर पूछे जाने वाले सवाल

क्या अकाउंट ज़रूरी है?

नहीं। कोई भी खेल सकता है। XP, streak, badge और हिस्ट्री सेव रखने के लिए साइन इन करें।

क्या मैं इसे दोबारा दे सकता हूं?

हां। आपका बेस्ट स्कोर सेव रहता है, और हर बार सवाल और जवाब शफ़ल होते हैं।