VishwaK03's picture
Upload 7 files
2c7cc75 verified
Raw History Blame Contribute Delete
4.27 kB
{
"integer_division_trap": {
"level_1": "πŸ’‘ Hint: You are dividing two integers. What happens to the decimal? (Watch video)",
"level_2": "⚠️ Error: Integer division (15/100) results in 0, not 0.15. (Watch video)",
"level_3": "πŸ›‘ Fix: Add '.0' to one of the numbers to perform float division. (Watch video)",
"title": "Integer Division Trap",
"concept": "In C, dividing two integers discards the decimal part completely.",
"fix": "Cast one variable to (float) or add .0 to constants.",
"bad": "float x = 15 / 100;",
"good": "float x = 15.0 / 100.0;"
},
"assignment_in_condition": {
"level_1": "πŸ’‘ Hint: Check the operator inside your 'if' statement. (Watch video)",
"level_2": "⚠️ Error: You are assigning (=) instead of comparing (==). (Watch video)",
"level_3": "πŸ›‘ Fix: Change '=' to '==' for comparison. (Watch video)",
"title": "Assignment vs Equality",
"concept": "Using single '=' inside 'if' assigns a value, which is usually true.",
"fix": "Use '==' for comparison.",
"bad": "if (x = 5) { ... }",
"good": "if (x == 5) { ... }"
},
"scanf_missing_ampersand": {
"level_1": "πŸ’‘ Hint: Scanf needs to know the memory address. (Watch video)",
"level_2": "⚠️ Error: You missed the '&' symbol in scanf. (Watch video)",
"level_3": "πŸ›‘ Fix: Add '&' before the variable name. (Watch video)",
"title": "Missing & in Scanf",
"concept": "Scanf requires a pointer to the variable location.",
"fix": "Add '&' operator.",
"bad": "scanf(\"%d\", val);",
"good": "scanf(\"%d\", &val);"
},
"array_out_of_bounds": {
"level_1": "πŸ’‘ Hint: Check your array index. (Watch video)",
"level_2": "⚠️ Error: You are accessing memory outside the array. (Watch video)",
"level_3": "πŸ›‘ Fix: Array indexes start at 0 and end at size-1. (Watch video)",
"title": "Array Out of Bounds",
"concept": "Accessing invalid indexes causes garbage values or crashes.",
"fix": "Ensure index < size.",
"bad": "int a[3]; a[3] = 5;",
"good": "int a[3]; a[2] = 5;"
},
"memory_leak": {
"level_1": "πŸ’‘ Hint: You allocated memory but didn't clean up. (Watch video)",
"level_2": "⚠️ Error: Dynamic memory (malloc) must be freed. (Watch video)",
"level_3": "πŸ›‘ Fix: Add 'free(ptr)' before return. (Watch video)",
"title": "Memory Leak",
"concept": "Memory from malloc stays occupied until you free it.",
"fix": "Use free() when done.",
"bad": "p = malloc(n); return;",
"good": "p = malloc(n); free(p); return;"
},
"null_pointer_dereference": {
"level_1": "πŸ’‘ Hint: This pointer might be pointing to nothing. (Watch video)",
"level_2": "⚠️ Error: You are writing to NULL. (Watch video)",
"level_3": "πŸ›‘ Fix: Initialize the pointer with a valid address. (Watch video)",
"title": "Null Pointer Crash",
"concept": "Dereferencing NULL causes a Segmentation Fault.",
"fix": "Assign valid address before use.",
"bad": "int *p = NULL; *p = 5;",
"good": "int v; int *p = &v; *p = 5;"
},
"uninitialized_variable": {
"level_1": "πŸ’‘ Hint: This variable has no value yet. (Watch video)",
"level_2": "⚠️ Error: Using uninitialized variable leads to garbage data. (Watch video)",
"level_3": "πŸ›‘ Fix: Assign a value (e.g., = 0) when declaring. (Watch video)",
"title": "Uninitialized Variable",
"concept": "Variables contain random memory junk until initialized.",
"fix": "Initialize on declaration.",
"bad": "int x; printf(\"%d\", x);",
"good": "int x = 0; printf(\"%d\", x);"
},
"string_equality_error": {
"level_1": "πŸ’‘ Hint: Can you compare strings using '==' in C? (Watch video)",
"level_2": "⚠️ Error: In C, '==' compares memory addresses of strings, not the text. (Watch video)",
"level_3": "πŸ›‘ Fix: Use the 'strcmp()' function from string.h. (Watch video)",
"title": "String Comparison Error",
"concept": "Strings are pointers in C; you must use strcmp for content comparison.",
"fix": "Use strcmp(str1, str2) == 0.",
"bad": "if (str == \"admin\")",
"good": "if (strcmp(str, \"admin\") == 0)"
}
}